Here is the way I have it setup on "status.x10hosting.com/status.php"
First make an include, and put this in it:
PHP Code:
<?php
$freeip = '66.232.109.231'; // Assuming Free Server
function serviceStatus($ip, $port) {
$handle = @fsockopen($ip, $port, $errno, $errstr, 1);
if (!$handle) {
$string = 'false';
} else {
$string = 'true';
@fclose($handle);
}
return $string;
}
?>
Then include this to any PHP you want it to be shown on. Next put this code in
PHP Code:
$http = serviceStatus($freeip, 80); // Chane 80 to the port, and http to the service or port.
// Display a nice output
if ($http == 'true') { echo '<span class="online">Online</span>'; ///Chate $http to whatever you change it to above.
} else { echo '<span class="offline">Offline</span>';}
Change the class to w/e, it can even be a fond too... I see this way easier, but thats my opinion.
Here is how to make an image
PHP Code:
<?php
ob_flush();
$ip = ''; // Set this as IP
// $port = $_GET['port']; // <-- Use this for ?port=portnumber
$port = ''; // <-- Set this for static port
function serviceStatus($ip, $port) {
$handle = @fsockopen($ip, $port, $errno, $errstr, 30);
if (!$handle) {
$string = 'Down';
} else {
$string = 'Online';
@fclose($handle);
}
return $string;
}
header("Content-type: image/png");
$status = serviceStatus($ip, $port);
$image = imagecreatefrompng('status.png');
$red = imagecolorallocate($image, 255, 000, 000);
$green = imagecolorallocate($image, 000, 100, 000);
$font = "arial.ttf";
if ($status == 'Online') { $color = $green; } else { $color = $red; }
imagettftext($image, 10, 0, 15, 11, $color, $font, $status);
imagepng($image);
imagedestroy($image);
ob_end_flush();
?>
Also you need status.png and arial.tff <-- Make sure both these files are in same dir as the php script.
Set $ip as the server ip, and then say you name it "status.php", run "status.php?port=80" to check port 80, and it will diplay up and down.
You can change the backround image by changing image.png