• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Need help with status online!!

Spetlex

OTCleverPage
Joined
Oct 5, 2012
Messages
42
Reaction score
1
Location
~/Spetlex
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:
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
 
works fine here, add var_dump($data); under fclose($sock);

Thnx for your reactions..
Still having the same error, but now with this above the errors: string '' (length=0)

@ haxborn i dont have the original anymore, but i deleted monster stuff and motd and the form with IP/Port

- - - Updated - - -

BUMP need to fix it!!
 
Back
Top