<?php
#######################################################################
# UD Server Status 1.0 #
# Copyright (C) 2005 by Andrew I. Poluosmak #
# Email: hide@address.com #
# Ukraine, Kiev 2005 #
#######################################################################
///////////////////////////////////////////////////////////////////////
// Example:
///////////////////////////////////////////////////////////////////////
// $patch = "patch to images"; //
// $site = "http://www.your.site"; //
// $server_status = new ServerStatus($site, $patch); //
// echo $server_status; //
///////////////////////////////////////////////////////////////////////
class ServerStatus
{
var $_STATUS; // Server status
var $_SRV; // Server link
var $_PATCH_IMG; // Patch to images
//--- Class Constructor ---//
function ServerStatus($site_link, $patch_img)
{
$this->_STATUS = NULL;
$this->_SRV = $site_link;
$this->_PATCH_IMG = $patch_img;
$this->getStatus();
}
//--- Engine (Publick function) ---//
function getStatus()
{
if ($this->_STATUS != NULL)
{
return $this->_imagesStatus($this->_STATUS);
} else {
$site = $this->_expLink($this->_SRV);
$check_url = @fsockopen($this->_server($site[0]), $site[1], $errno, $errstr, 20);
if (!$check_url)
{
$this->_STATUS = "dead";
} else {
$this->_STATUS = "life";
}
return $this->_imagesStatus($this->_STATUS);
}
}
//--- Private functions ---//
function _expLink($link)
{
$exp_link = str_replace("::", ":", $link);
list($site,$port) = explode (':', $exp_link);
if (empty($port)){
$port = 80;
}
$array = array($site, $port);
return $array;
}
function _server($site)
{
if (strstr($site,"/"))
{
$site = substr($site, 0, strpos($site, "/"));
}
return $site;
}
function _imagesStatus($status)
{
$array = array("dead" => "dead.gif", "life" => "life.gif");
return $this->_PATCH_IMG.$array[$status];
}
}
?>