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
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,
second one,
third one,
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 (
) and offline.gif (
). If you want to change you'll have to edit the script.
Just copy and paste this into a php file.
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">
serverid should be what you name the servers in the script.
Explanation
The code below shows three ways of setting an array.
First one,
will use the next number in the array. This become zero as arrays start on zero and there were none set before this.array('123.123.123', 123),
second one,
... you guessed it, it will be number 1111 => array('123.123.123.123', 123),
third one,
will of course be http. This isn't so hard is it... Remember to use single quotes ( ' ) if you use anything else but numbers.'http' => array('123.123.123.123', 123),
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 (
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');
}
?>