Results 1 to 3 of 3

Thread: Server UP time Script

  1. #1
    dharmil's Avatar
    dharmil is offline x10 Elder
    Join Date
    Sep 2005
    Location
    Avenel New Jersey
    Posts
    828

    Server UP time Script

    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 () and offline.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');
    }
    
    ?>

  2. #2
    bigguy's Avatar
    bigguy is offline Retired
    Join Date
    Mar 2005
    Location
    Canada
    Posts
    5,426

    Re: Server UP time Script

    Nice little tutorial man, very nice.
    P.C. Tweakr - For all your computer and internet support
    P.C. Tweakr - For all your SMF help and support

  3. #3
    dharmil's Avatar
    dharmil is offline x10 Elder
    Join Date
    Sep 2005
    Location
    Avenel New Jersey
    Posts
    828

    Re: Server UP time Script

    Thanks

Similar Threads

  1. Script that forwards you to a secondary server if main server is offline
    By Christopher in forum Scripts, 3rd Party Apps, and Programming
    Replies: 9
    Last Post: 03-05-2008, 06:27 AM
  2. Server Load PHP Script
    By TheJeffsta in forum Free Hosting
    Replies: 9
    Last Post: 05-17-2006, 01:47 PM
  3. Server time of X10
    By randomize in forum Off Topic
    Replies: 3
    Last Post: 03-22-2006, 04:03 PM
  4. FTP server time out
    By Skyline4life in forum Free Hosting
    Replies: 2
    Last Post: 06-06-2005, 01:37 PM
  5. Server Time
    By Bryon in forum Free Hosting
    Replies: 1
    Last Post: 05-16-2005, 10:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers