...

View Full Version : PHP Host



BinaryX
10-03-2010, 05:54 PM
<?php
/*
* Pings all hosts and prints their status.
* @author BinaryX
*/
$servers = array("BinaryX@binaryx.nl@80","Server2@127.0.0.1@27015");
$table_height = count($servers) * 10;
?>

<table border="1" width="<?php $table_height ?>">
<tr><td>Name</td><td>Ip</td><td>Port</td><td>Status</td></tr>
<?php
for ($i = 0; $i <= count($servers); $i++) {
echo '<tr>';
$server_info = explode("@", $servers[$i]);
$server_name = $server_info[0];
$server_ip = $server_info[1];
$server_port = (int) $server_info[2];
$fp = fsockopen(trim($server_ip), trim($server_port), $errstr, $errno, $timeout);
$status = $fp ? "ONLINE" : "OFFLINE";

echo '<td>' . $server_name . '</td><td>' . $server_ip . '</td><td>' . $server_port . '</td><td>'.$status.'</td>';
echo '</tr>';
$i++;
}
?>
</table>



Displays the first row in the table just fine with the status online but it fails to parse the second one (all the variables are empty).

Why?

PHP you keep amazing me everytime lol.

BinaryX
10-03-2010, 06:37 PM
For the error browse to:


http://binaryx.nl/query/online.php

DrDOS
10-03-2010, 06:57 PM
You've got three errors in your code.
$timeout is not defined. I just set $timeout = 30;
You have <= in the for loop, should just be <.
You have two $i++, one in the for loop, one at the bottom. Remove the one at the bottom.

BinaryX
10-03-2010, 07:10 PM
Thanks worked.

BinaryX
10-03-2010, 07:34 PM
Ok now it always returns OFFLINE but the servers that are in the array are ONLINE.
Im trying to check if an specific Counterstrike server is online or offline.

Why are there always problems with this?



$servers = array("Counterstrike Server #1@89.238.160.184@27015", "Counterstrike Server #2@89.44.246.135@27015");


It works fine if i set binaryx.nl as address and the port as 80




Warning: fsockopen() [function.fsockopen]: unable to connect to 89.238.160.184:27015 (Connection timed out) in /customers/binaryx.nl/binaryx.nl/httpd.www/query/online.php on line 29

Warning: fsockopen() [function.fsockopen]: unable to connect to 89.44.246.135:27015 (Connection timed out) in /customers/binaryx.nl/binaryx.nl/httpd.www/query/online.php on line 29

DrDOS
10-03-2010, 08:13 PM
I put that code in my page, the first server is on line, the second is not. I put the second server URL in the browser window with the port#, it also checks offline.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum