MyBB Community Forums

Full Version: php status checker error :/
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys, so i'm using the dark fusion theme.

What i'm trying to do is add a server status checker that can ping to an ip and port and return a value of online or offline etc.

I have the script.

It works 100% perfect if i just put it in a php file and then have just a white page etc.

I want to create a page that blends into my template.

however, when i do this, the html part works fine...but the second i add php to the globaltemplates it gives me an error.

Here is a link to the plane php file that works perfect.

http://RuneCentre.com/test.php

Works perfect, but the file doesn't have the template background, header, footer etc.

Now, when you go here:

http://RuneCentre.com/statuschecker.php

You receive an error.


Why? It works fine if i remove the php, but as soon as i add it, that error occurs.

Here is what the statuschecker.php file looks like.


<?php 

define('IN_MYBB', 1); require "./global.php";

add_breadcrumb("Status Checker", "statuschecker.php"); 

eval("\$html = \"".$templates->get("status_checker")."\";"); 

output_page($html);

?>
And then in globaltemplates, i have a template titled status_checker

here is the contents of that.

<head>
<title align="center">Status Checker</title>
{$headerinclude}
</head>
<body align = "center">
{$header}
<table border="0" cellspacing="1" cellpadding="4" class="tborder">
<tr>
<td class="thead"><span class="smalltext"><strong><center>Status Checker</center></strong></span></td>
</tr>

<form action="" method="get"><center>
<title>Rune-Core - Status Checker</title>
<table border="0">
	<tr>
		<td>
			IP:
		</td>
	</tr>
	<tr>
		<td>
			<input type="text" name="address" />
		</td>
	</tr>
	<tr>
		<td>
			Port:
		</td>
	</tr>
	<tr>
		<td>
			<select name="port">
				<option>43594</option>
				<option>5555</option>
				<option>80</option>
			</select>
		</td>
	</tr>
<tr>
		<td align="right">
			<input type="submit" name="submit" value="Check" />
		</td>
	</tr>
</table>
</form>
</center>

<?php

$IP = $_GET['address'];
$Port = $_GET['port'];

$Check = fsockopen($IP, $Port, $errno, $errstr, .5);

if(isset($_GET['submit'])) {
	if($Check) {
		echo "<b>IP:</b> " . $IP . "<br>";
		echo "<b>Port:</b> " . $Port . "<br>";
		echo "<b>Status:</b> <font color='green'>Online!</font>" . "<br>";
	} else {
		echo "<b>IP:</b> " . $IP . "<br>";
		echo "<b>Port:</b> " . $Port . "<br>";
		echo "<b>Status:</b> <font color='red'>Offline.</font>" . "<br>";
	}
}
?>

{$footer}
</body>
</html>

If i remove this code in the template file


<?php

$IP = $_GET['address'];
$Port = $_GET['port'];

$Check = fsockopen($IP, $Port, $errno, $errstr, .5);

if(isset($_GET['submit'])) {
	if($Check) {
		echo "<b>IP:</b> " . $IP . "<br>";
		echo "<b>Port:</b> " . $Port . "<br>";
		echo "<b>Status:</b> <font color='green'>Online!</font>" . "<br>";
	} else {
		echo "<b>IP:</b> " . $IP . "<br>";
		echo "<b>Port:</b> " . $Port . "<br>";
		echo "<b>Status:</b> <font color='red'>Offline.</font>" . "<br>";
	}
}
?>

The page will look just like the theme and it will display the html, but no function will work of course.

I hope I have explained this well enough.

If anyone can help, I'de greatly appreciate it!

Thanks in advance.

p.s

incase i fool around, here is the error.


Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/pronyma/public_html/statuschecker.php(7) : eval()'d code on line 51
Remove any whitespace after "?>"
^ I don't understand what you mean?

I have tightend up the code, and still receive the error.

Anyone else have a more knowledgable/detailed answer?
After your ending php tag "?>" are there any spaces ?
(2012-06-15, 09:56 PM)Frank.Barry Wrote: [ -> ]After your ending php tag "?>" are there any spaces ?

Hey, thanks for the fast reply.

Here is how the code looks now.


<?php
$IP = $_GET['address'];
$Port = $_GET['port'];
$Check = fsockopen($IP, $Port, $errno, $errstr, .5);
if(isset($_GET['submit'])) {
	if($Check) {
		echo "<b>IP:</b> " . $IP . "<br>";
		echo "<b>Port:</b> " . $Port . "<br>";
		echo "<b>Status:</b> <font color='green'>Online!</font>" . "<br>";
	} else {
		echo "<b>IP:</b> " . $IP . "<br>";
		echo "<b>Port:</b> " . $Port . "<br>";
		echo "<b>Status:</b> <font color='red'>Offline.</font>" . "<br>";
	}
}
?>{$footer}


There are no spaces, and if i press enter after the ?> and have the {footer} thing under it, it still isn't working.
unless you have the PHP In Templates plugin, what you want to do is not going to work.

Why even both with the template system in this case? Just hard code it all in the main php file and be done with it
i'm just trying to make a custom php page on my site.

I followed the steps todo so, and when i insert my script, it gives me that error.
code

<?php 
define('IN_MYBB', 1); require "./global.php";
add_breadcrumb("Status Checker", "statuschecker.php"); 
$IP = $_GET['address'];
$Port = $_GET['port'];
if(isset($_GET['submit'])) {
	$Check = fsockopen($IP, $Port, $errno, $errstr, .5);
    if($Check) {
        $checker = "<b>IP:</b> " . $IP . "<br>";
        $checker .= "<b>Port:</b> " . $Port . "<br>";
        $checker .= "<b>Status:</b> <font color='green'>Online!</font>" . "<br>";
    } else {
        $checker = "<b>IP:</b> " . $IP . "<br>";
        $checker .= "<b>Port:</b> " . $Port . "<br>";
        $checker .= "<b>Status:</b> <font color='red'>Offline.</font>" . "<br>";
    }
}
eval("\$html = \"".$templates->get("status_checker")."\";");
output_page($html);
?>

template
<head>
 <title align="center">Status Checker</title>
 {$headerinclude}
 </head>
 <body align = "center">
 {$header}
 <table border="0" cellspacing="1" cellpadding="4" class="tborder">
 <tr>
 <td class="thead"><span class="smalltext"><strong><center>Status Checker</center></strong></span></td>
 </tr>

 <form action="" method="get"><center>
 <title>Rune-Core - Status Checker</title>
 <table border="0">
     <tr>
         <td>
             IP:
         </td>
     </tr>
     <tr>
         <td>
             <input type="text" name="address" />
         </td>
     </tr>
     <tr>
         <td>
             Port:
         </td>
     </tr>
     <tr>
         <td>
             <select name="port">
                 <option>43594</option>
                 <option>5555</option>
                 <option>80</option>
             </select>
         </td>
     </tr>
 <tr>
         <td align="right">
             <input type="submit" name="submit" value="Check" />
         </td>
     </tr>
 </table>
 </form>
 </center>
 {$checker}
 {$footer}
 </body>
 </html>
Thank you so much! Working!!

Thank you!![/align]