Minecraft server status page,

Post here is you are having problems with any of the tutorials.
Post Reply
LoGDamo
Posts: 3
Joined: Thu May 19, 2011 12:27 am

Minecraft server status page,

Post by LoGDamo »

I appear to keep getting this error and don't know why ?!?
Probs something very easy but i don't know.

Here is the error:
Parse error: syntax error, unexpected $end in C:\wamp\www\MSC\status.php on line 44
Here are my files,

status.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

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

?>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style type="text/css">
	table 		{ width 600px; border-collapse: collapse; }
	td, th  	{ padding: 4px; border: solid 1px #444; }
	.online 	{ background: #090 }
	.offline	{ background: #900 }
</style>

</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>
		</tbody>
	</table>

</body>
</html>
init.inc.php:
<?php

$servers = array(

	array('83.222.240.254', '30465'),
	array('192.168.2.10', '25565'),
);

error_reporting(0);
$path = dirname(_FILE_);

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

?>
minecraft_server.inc.php:
<?php

function server_online($server, $port){
	fsockopen($server, $port, $errno, $errstr, 0.1);

	return($errno === 0);		
}
	
?>
Thanks
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minecraft server status page,

Post by jacek »

foreach ($servers as $server){
You do not have a closing } to this loop.

Also, you should not be disabling error_reporting :? this would hide any errors leaving you with no way of debugging problems.

And can you make sure to use the php button when posting code on the forum, not the quote one ;)
Image
LoGDamo
Posts: 3
Joined: Thu May 19, 2011 12:27 am

Re: Minecraft server status page,

Post by LoGDamo »

jacek wrote:
foreach ($servers as $server){
You do not have a closing } to this loop.

Also, you should not be disabling error_reporting :? this would hide any errors leaving you with no way of debugging problems.

And can you make sure to use the php button when posting code on the forum, not the quote one ;)
Ok my status.php now looks like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

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

?>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<style type="text/css">
	table 		{ width 600px; border-collapse: collapse; }
	td, th  	{ padding: 4px; border: solid 1px #444; }
	.online 	{ background: #090 }
	.offline	{ background: #900 }
</style>

</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>
		
		
		</tbody>
	</table>

</body>
</html>
but im appear to be getting all these errors
Image
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minecraft server status page,

Post by jacek »

The first error is causing all of the others ;) _FILE_ should be __FILE__ with 2 _ either side of it.
Image
LoGDamo
Posts: 3
Joined: Thu May 19, 2011 12:27 am

Re: Minecraft server status page,

Post by LoGDamo »

Dude you are awesome :)

You got my subscription thanks alot :)
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minecraft server status page,

Post by jacek »

I am, yes 8-)

Glad you got it working :)

you had it basically right, just a few typos.
Image
User avatar
pasqo83
Posts: 106
Joined: Sat May 14, 2011 6:23 am

Re: Minecraft server status page,

Post by pasqo83 »

jacek wrote:I am, yes 8-)

Glad you got it working :)

you had it basically right, just a few typos.
All I want to know is how the hell do you manage to remember all of these codes and where it goes. What book are you eating at night? :lol: Im reading all of these to understand but its just sort of happening :(
  • Empty your mind, be formless like water. If you put water into a cup, it becomes the cup. You put water into a bottle and it becomes the bottle. You put it in a teapot it becomes the teapot. Now, water can flow or it can crash. Be water my friend.
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Minecraft server status page,

Post by jacek »

I don't remember everything, there is no need too as we have php.net. As long as you know that a function to do the thing you want exists you can just look up how to use it.

Its just practice I guess.
Image
Post Reply