Server UP time Script

dharmil

New Member
Messages
1,656
Reaction score
0
Points
0
Description

This script will as the previously posted script, check the current online status but it will output a image instead of text.

Server IPs and ports are defined inside the script so people can't use it script to check whatever they like.

Usage

Copy and save the below script into a php file and use

Code:
<img src="scriptname.php?server=serverid">
scriptname.php should be replaced with whatever name you give the script.
serverid should be what you name the servers in the script.

Explanation

The code below shows three ways of setting an array.

First one,
array('123.123.123', 123),
will use the next number in the array. This become zero as arrays start on zero and there were none set before this.

second one,
11 => array('123.123.123.123', 123),
... you guessed it, it will be number 11

third one,
'http' => array('123.123.123.123', 123),
will of course be http. This isn't so hard is it... Remember to use single quotes ( ' ) if you use anything else but numbers.

Fourth and last one is the same as the first. It will use the next number in the array which is now 12 because we set number 11 before.

Script

You either need to save or create two images and put them in the same folder as the script. online.gif (
0f9f45958d.gif
) and offline.gif (
d6a1387001.gif
). If you want to change you'll have to edit the script.

Just copy and paste this into a php file.

Code:
<?php

# Change the below as following
# array('IP number', Port number);
# Remove the ones you don't use.

$servers = array(
           array('123.123.123.123', 123), # Next number in array, zero if first
 11     => array('123.123.123.123', 123), # Number 11
 'http' => array('123.123.123.123', 123), # Named http
           array('123.123.123.123', 123), # This becomes 12 because have set 11
);

function getConnectionStatus($address, $port)
{
 $sock = fsockopen($address, $port, $errno, $errstr, 5);
 if (!empty($sock)) $status = true;
 else $status = false;
 fclose($sock);
 return $status;
}

if (isset($_GET['server']) && array_key_exists($_GET['server'], $servers))
{
 $status = getConnectionStatus($servers[$_GET['server']][0], $servers[$_GET['server']][1]);
 header("Cache-Control: no-cache, must-revalidate");
 header("Expires: Sat, 16 Aug 1986 05:00:00 GMT");
 header('Content-type: image/gif');
 if ($status) @readfile('online.gif');
 else @readfile('offline.gif');
}

?>
 
Top