Thread: Adding server "online" / "Offline" to website

Results 1 to 7 of 7
  1. #1 Adding server "online" / "Offline" to website 
    woofdawg23
    Guest
    go to your website, add this php code:

    Code:
    <?php
    $ip = "SERVER IP"; //put your ipaddress here
    $port= "SERVER PORT"; //the port number
    $online = '<font color="green">Online</font>'; //This can be text or image
    $offline = '<font color="red">Offline</font>';   //This can be text or image
    if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) //Checks the server's status 
    {
    echo "$offline"; //When server status is offline, output this
    }
    else
    {
    echo "$online"; //Else, output this
    }
    ?>
    Change server ip + port to your server ip + port and this will say in green "online" if server online or "offline" if server offline.
     

  2. #2  
    Registered Member

    Join Date
    Feb 2007
    Age
    25
    Posts
    6,415
    Thanks given
    354
    Thanks received
    323
    Rep Power
    5000
    does this even work?
    [Only registered and activated users can see links. ]

    Menacescape - Runescape Private server
    Come to Menacescape. We've been online for over two years with an active community!
     

  3. #3  
    Professional Upsetter


    Join Date
    Jul 2006
    Posts
    5,392
    Thanks given
    163
    Thanks received
    447
    Rep Power
    2040
    Not even your own work...
    Ex-super moderator of Rune-Server.org and RSBot.org
     

  4. #4  
    MybGod
    Guest
    [PHP]<?php
    $ip = "google.com";
    $port= "80";

    if (!$sock = @fsockopen($ip, $port, $num, $error, 5))
    {
    echo "<font color=\"red\">Offline</font>";
    } else {
    echo "<font color=\"green\">Online</font>";
    }
    ?>[/PHP]
    Would do fine, why have $online and $offline?
    If you feel like having them, why not use
    [PHP]echo $online/PHP]
    instead of
    [PHP]echo "$online"/PHP]


    Quote Originally Posted by Im An Angel View Post
    does this even work?
    Sure it does, but by refreshing a lot you could try and crash a RuneScape Private Server even
    Most of them have nulling protection now though.
     

  5. #5  
    Registered Member
    Join Date
    Nov 2006
    Posts
    699
    Thanks given
    1
    Thanks received
    32
    Rep Power
    524
    Quote Originally Posted by Inside Sin View Post
    Not even your own work...
    F*ck off; all server socket opens written in PHP are all the same, literally.

    Might I suggest you explain the other parameters so they don't have to wait FIVE seconds for a page to load?

    $num is the error number you'd get if there was something wrong.
    $error is the error message in a string -- basically if the server is offline, it says "The socket you attempted failed because the server is offline", or something similar.
    The five indicates the timeout.

    If your timeout is set to five, then the page is going to attempt to check the server. If the server is offline, the page will not load for five seconds, because the server socket will continue to check for five seconds before actually sending the whole page to the client.

    Therefore... I suggest you set the timeout to a lower value if you don't want the page taking five seconds to load, or... you could do like a pre-load technique, although I haven't worked with that much. If you run the "server" on the same "box" as the webserver, then you should definately set it to a really low value, maybe as low as 0.001 seconds, since a reply for an online status to localhost only takes less than a millisecond.

    tl;dr -- USE A LOWER TIMEOUT.

    ~Z
     

  6. #6  
    Donator

    Scim's Avatar
    Join Date
    Apr 2007
    Age
    28
    Posts
    739
    Thanks given
    61
    Thanks received
    16
    Rep Power
    238
    Zachera knows his php.. and ummm yeah just as MyBGod asked, why put double quotes when echoing a variable
     

  7. #7  
    tyler_wut
    Guest
    My server just says offline always. o.O
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •