View Full Version : PHP Host

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

<table border="1" width="<?php $table_height ?>">
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>';

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).


PHP you keep amazing me everytime lol.

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


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.

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

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@", "Counterstrike Server #2@");

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

Warning: fsockopen() [function.fsockopen]: unable to connect to (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 (Connection timed out) in /customers/binaryx.nl/binaryx.nl/httpd.www/query/online.php on line 29

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.