PHP Server Online/Offline Status Checker

This will output an “online” image if the server you are trying to connect to is online, and “offline” if it is offline. It supports multiple ports…

<?php
/*
Online/Offline Status Webchecker by Daniel Austin MBCS.
Multiple ports option added by Niall Davies.
*/
$online = "online.gif"; /* Link to Online image */
$offline = "offline.gif";    /* Link to Offline image */
/* NO MORE CONFIGURATION!!! */
$host = $_SERVER["QUERY_STRING"];
if ($host == "")
$host = "127.0.0.1:80";
if (StrStr($host, ":")) {
$port = SubStr($host, StrPos($host, ":")+1, StrLen($host));
$host = SubStr($host, 0, StrPos($host, ":"));
settype($port, "integer");
} else {
$port = 80;
}
$host = "tcp://$host";
$is_online = false;
$fd = @fsockopen($host, $port, $errno, $errmsg, 2);
if ($fd)
{
$is_online = true;
@fclose($fd);
}
if ($is_online)
$img = $online;
else
$img = $offline;
$imgsize = @filesize($img);
header("Content-type: image/gif");
header("Content-length: $imgsize");
readfile($img);
die;
?>

Leave a Reply

Your email address will not be published. Required fields are marked *