Page 1 of 1

[HELP!] Minecraft Server Status Page

Posted: Wed Aug 31, 2011 4:19 pm
by XCC
Hello,

I have been following this video...

...but it's not working.

First off here is my code:
init.inc.php
<?php

$servers = array(
	array('192.168.1.70', '25565'),
	array('127.0.0.1', '25565'),
);

error_reporting(0);

$path = dirname(__FILE__);

include("{$path}/lib/minecraft_server.inc.php");

?>
minecraft_server.inc.php
<?php

// Checks if the given server is online.
function server_online($server, $port){
	fsockopen($server, $port, $errno, $errstr, 0.1);
	
	return ($errno === 0);
}

?>
index.php
<?php

include('core/init.inc.php');

?>
<!DOCTYPE HTML>
<html>
<head>
<title>Minecraft Server Status</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>

<table>
<thead>
<tr>
<th>Server</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php

foreach($servers as $server){
	$online = server_online($server[0], $server[1]);
	
	?>
    <tr>
    <td><?php echo $server[0], ':', $server[1]; ?></td>
    <td class="<?php echo ($online) ? 'online' : 'offline'; ?>"><?php echo ($online) ? 'Online' : 'Offline'; ?></td>
    </tr>
    <?php
}

?>
</tbody>
</table>
</body>
</html> 
No matter what i do it always shows as red/offline even if the server is online. What's the problem?

Re: [HELP!] Minecraft Server Status Page

Posted: Wed Aug 31, 2011 6:53 pm
by jacek
The code looks okay, try turning the timeout up a little to around 0.5 and see if that helps.

Re: [HELP!] Minecraft Server Status Page

Posted: Wed Aug 31, 2011 7:15 pm
by XCC
jacek wrote:The code looks okay, try turning the timeout up a little to around 0.5 and see if that helps.
Turning the timeout up didn't work either.

Can it have something to do with the server.properties of the minecraft server? Right now all the settings are at the default. Other than that i don't know what to do :shock:

Re: [HELP!] Minecraft Server Status Page

Posted: Wed Aug 31, 2011 7:59 pm
by jacek
Hmm, try removing the
error_reporting(0);
line and see if you get any errors.

There is nothing to do with the server.properties file that could affect this, there is nothing specific about the minecraft server, this is really a check to see if a port is being used more than anything.

Re: [HELP!] Minecraft Server Status Page

Posted: Wed Aug 31, 2011 8:13 pm
by XCC
jacek wrote:Hmm, try removing the
error_reporting(0);
line and see if you get any errors.

There is nothing to do with the server.properties file that could affect this, there is nothing specific about the minecraft server, this is really a check to see if a port is being used more than anything.
Removing error reporting gives me these 2 errors on the page.
Warning: fsockopen() [function.fsockopen]: unable to connect to 192.168.1.70:25565 (Connection timed out) in /home/content/89/6942189/html/dev/core/lib/minecraft_server.inc.php on line 5

Warning: fsockopen() [function.fsockopen]: unable to connect to 127.0.0.1:25565 (Connection refused) in /home/content/89/6942189/html/dev/core/lib/minecraft_server.inc.php on line 5

Re: [HELP!] Minecraft Server Status Page

Posted: Thu Sep 01, 2011 9:42 pm
by jacek
That just means a connection could not be made.

Can you connect to the server in game ? A firewall or somethign may be blocking the connection.