Page 1 of 1

Minecraft server status page,

Posted: Thu May 19, 2011 12:31 am
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

Re: Minecraft server status page,

Posted: Thu May 19, 2011 12:36 am
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 ;)

Re: Minecraft server status page,

Posted: Thu May 19, 2011 11:56 am
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

Re: Minecraft server status page,

Posted: Thu May 19, 2011 1:47 pm
by jacek
The first error is causing all of the others ;) _FILE_ should be __FILE__ with 2 _ either side of it.

Re: Minecraft server status page,

Posted: Thu May 19, 2011 3:06 pm
by LoGDamo
Dude you are awesome :)

You got my subscription thanks alot :)

Re: Minecraft server status page,

Posted: Thu May 19, 2011 3:13 pm
by jacek
I am, yes 8-)

Glad you got it working :)

you had it basically right, just a few typos.

Re: Minecraft server status page,

Posted: Thu May 19, 2011 3:58 pm
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 :(

Re: Minecraft server status page,

Posted: Thu May 19, 2011 4:13 pm
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.