Gerald Kacka Gerald Kacka - 5 months ago 16
PHP Question

PHP $_GET Help to create a link

Iam try to create a simple page to get IP and Port with $GET

Example index.php?ip=193.192.58.12&port=27016

I get server error with my code

if (isset($_GET['ip']) && $_GET["port"]) {

$ip = $_GET["ip"];
$queryport = $_GET["port"];


$ip = '';
$queryport = ;

$socket = @fsockopen("udp://".$ip, $queryport , $errno, $errstr, 1);

stream_set_timeout($socket, 1);
stream_set_blocking($socket, TRUE);
fwrite($socket, "\xFF\xFF\xFF\xFF\x54Source Engine Query\x00");
$response = fread($socket, 4096);
@fclose($socket);

$packet = explode("\x00", substr($response, 6), 5);
$server = array();

$server['name'] = $packet[0];
$inner = $packet[4];
$server['players'] = ord(substr($inner, 2, 1));
$server['playersmax'] = ord(substr($inner, 3, 1));

var_dump (json_encode( $server ));

} else {

echo "Serveri nuk ekziston";
}

Answer

The following code is causing a problem by overwriting/removing the values that you've just grabbed from $_GET:

$ip = $_GET["ip"];  
$queryport = $_GET["port"]; 

$ip = '';
$queryport = ;       //    <<-- syntax error

Remove $ip = ''; and $queryport = ; and test again.

Also remove the @ from @fsockopen so you can see when it breaks.

Comments