[HELP!] Minecraft Server Status Page

Post here is you are having problems with any of the tutorials.
Post Reply
XCC
Posts: 3
Joined: Wed Aug 31, 2011 3:53 pm

[HELP!] Minecraft Server Status Page

Post 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?
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: [HELP!] Minecraft Server Status Page

Post by jacek »

The code looks okay, try turning the timeout up a little to around 0.5 and see if that helps.
Image
XCC
Posts: 3
Joined: Wed Aug 31, 2011 3:53 pm

Re: [HELP!] Minecraft Server Status Page

Post 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:
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: [HELP!] Minecraft Server Status Page

Post 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.
Image
XCC
Posts: 3
Joined: Wed Aug 31, 2011 3:53 pm

Re: [HELP!] Minecraft Server Status Page

Post 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
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: [HELP!] Minecraft Server Status Page

Post 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.
Image
Post Reply