Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function getRobloxUserIdByUsername($username) {
$url = "https://api.roblox.com/users/get-by-username?username=" . urlencode($username);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Важно для редиректов
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); // Принудительно IPv4
// Если проблема с DNS:
// curl_setopt($ch, CURLOPT_DNS_SERVERS, '8.8.8.8,1.1.1.1');
$response = curl_exec($ch);
if (curl_errno($ch)) {
return ['error' => 'CURL Error: ' . curl_error($ch)];
}
curl_close($ch);
$data = json_decode($response, true);
if (isset($data['Id'])) {
return $data['Id'];
} else {
return ['error' => 'User not found'];
}
}
// Пример использования
$username = 'Roblox';
$userId = getRobloxUserIdByUsername($username);
if (is_array($userId) && isset($userId['error'])) {
echo "Ошибка: " . $userId['error'];
} else {
echo "ID пользователя $username: " . $userId;
}
?>