Hey people,
Today i was editing my server status for mu website, which displays players online and uptime.
Before i changed it, it worked fine but now it gives me some errors.
Errors:
and the script's output is
When it was with $_POST it worked very good, but when I put in default values (ip + port) it gives me the errors above.
Here is the script:
Thanks alot if you can help me!
Spetlex
Today i was editing my server status for mu website, which displays players online and uptime.
Before i changed it, it worked fine but now it gives me some errors.
Errors:
Code:
( ! ) Notice: Undefined offset: 1 in D:\wamp\www\OTCleverPage\status.php on line 14
( ! ) Notice: Undefined offset: 2 in D:\wamp\www\OTCleverPage\status.php on line 14
( ! ) Notice: Undefined offset: 1 in D:\wamp\www\OTCleverPage\status.php on line 16
( ! ) Notice: Undefined offset: 1 in D:\wamp\www\OTCleverPage\status.php on line 17
and the script's output is
Code:
Online!
Players: ??? / ???
Uptime: 0h 0m
When it was with $_POST it worked very good, but when I put in default values (ip + port) it gives me the errors above.
Here is the script:
PHP:
<?php
$address = htmlentities(strtolower("127.0.0.1"));
$port = "7171";
@$sock = fsockopen ($address, $port, $errno, $errstr, 1);
if(!$sock) echo "<span style='color:red;'>Offline</span>"; else {
$info = chr(6).chr(0).chr(255).chr(255).'info';
fwrite($sock, $info);
$data='';
while (!feof($sock))$data .= fgets($sock, 1024);
fclose($sock);
preg_match('/players online="(\d+)" max="(\d+)"/', $data, $matches);
$players = ''.$matches[1].' / '.$matches[2];
preg_match('/uptime="(\d+)"/', $data, $matches);
$h = floor($matches[1] / 3600);
$m = floor(($matches[1] - $h*3600) / 60);
$uptime = ''.$h.'h '.$m.'m';
if(empty($players) or $players == " / ") $players = "??? / ???";
if(empty($uptime)) $uptime = "???";
if(empty($monsters)) $monsters = "???";
if(empty($motd)) $motd = "???";
echo "
<span style='color:green;'>Online!</span><br />
Players: $players <br />
Uptime: $uptime<br />
";
}
?>
Thanks alot if you can help me!
Spetlex