05.11.2011, 19:09
If you're using it in an iframe you could just:
PHP код:
<html>
<script type="text/javascript">
setInterval ( "reloadPage()", 5000 );
function reloadPage ( )
{
window.location.reload();
}
</script>
<?php
getstats("24.111.46.103", "7777");
function getstats($ip, $port)
{
$fp = fsockopen('udp://' . $ip, $port, $errno, $errstr,0.0);
if (!$fp)
{
echo "offline";
}
else
{
$packet = 'SAMP';
$packet .= chr(strtok($ip, '.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr(strtok('.'));
$packet .= chr($port & 0xFF);
$packet .= chr($port >> 8 & 0xFF);
fwrite($fp, $packet.'i');
fread($fp, 11);
$is_passworded = ord(fread($fp, 1));
$plr_count = ord(fread($fp, 2));
$max_plrs = ord(fread($fp, 2));
$strlen = ord(fread($fp, 4));
$hostname = htmlentities(fread($fp, $strlen));
$strlen = ord(fread($fp, 4));
$gamemode = htmlentities(fread($fp, $strlen));
$strlen = ord(fread($fp, 4));
$mapname = htmlentities(fread($fp, $strlen));
if($is_passworded == 1)
{
$is_passworded = "yes";
}
else if($is_passworded == 0)
{
$is_passworded = "no";
}
echo "Hostname : $hostname " . "<br>";
echo "Gamemode : $gamemode ". "<br>";
echo "Map : $mapname ". "<br>";
echo "Players: $plr_count/$max_plrs". "<br>";
echo "Passoword: $is_passworded". "<br>";
fwrite($fp, $packet.'c');
fread($fp, 11);
fclose($fp);
}
}
?>
</html>