Results 1 to 9 of 9

Thread: Script to detect website status

  1. #1
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Script to detect website status

    Hello all,

    I am looking for a script to detect the presence of a website (my home server), and to display text depending on whether the site is accessible or not.

    The site is www.serberus.r8.org (Serberus is the network name of my system), that site will redirect to a longer url - it's a forwarder. You will probably get a page not found error as my server is usually off.

    Because the server is rarely on, I need the script to check if it's online and write a link to the server if it is.

    For example:
    Server is online: Script writes "Serberus Online"
    Server is offline: Script writes "Serberus Unavaliable"

    If you have any questions at all, please feel free to ask as this script is highly desired.

    Regards
    cr3ative

    edit: My 888th post
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by cr3ative
    I am looking for a script to detect the presence of a website (my home server), and to display text depending on whether the site is accessible or not.
    With which language in particular? It should be possible with any decent server-side language and it's possible client-side, too (though only with certain browsers).

    Mike

  3. #3
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    The page which displays the text can't be on my server, so I would have to use my personal ISP space, and I'm not sure if they support many server-side technologies.

    In an ideal situation, it would be made with javascript, but I'm sure I can ask my ISP to install a server-side application or two.

    It's also worth noting that when it comes to server-side, I'm useless. I can tinker with .htaccess and mod.rewrite, but that's about it.

    Thanks for your time
    cr3ative
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  4. #4
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by mwinter
    [...] it's possible client-side, too
    Unfortunately, I was mistaken there. Whilst the XMLHttpRequest object can be used in some user agents to make HTTP requests to a remote server, there are security restrictions which mean requests can only go to the originating server for the current document.

    So, you're back to only having a server-side option (well, unless you want to write - and sign[!] - a small Java applet). It can certainly be done with PHP (I'm looking for the best way, at the moment).

    Mike

  5. #5
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much for your time on this matter. I look forward to your findings.

    I can also PM you my FTP access details if need be to set this up, as I am useless with PHP.

    edit: My ISP space supports the following: Perl & SSI, PHP Version 4.1.2

    Cheers
    cr3ative
    Last edited by cr3ative; 01-08-2005 at 01:22 PM.
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    A basic implementation would be

    PHP Code:
    <?php
      $host 
    'your domain name';
      if(
    $socket fsockopen($host80$errno$errstr30)) {
        echo 
    'The content you want to insert';
        
    fclose($socket);
      }
    ?>
    This simply attempts to connect to the address (name or IP) identified in host. If the connection succeeds, a string will be written into the location of the code. I take it that the IP address of your server is static?

    The host name should be just a name: don't add a scheme (i.e. http://).

    The last argument in the fsockopen call is the timeout before the connection aborts. You'll probably want lower than 30 (otherwise users might be waiting for thirty seconds before they get a complete response from your server), but don't make it too low otherwise you'll get a false-positive if network traffic is high. In my brief tests, my local Web server automatically cut out before the timeout (at around twenty two seconds) so you can't specify an excessive timeout period anyway.

    I don't guarantee that this will work: though I didn't find any security restrictions mentioned, there might be some of which I'm not aware.

    Mike

  7. #7
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    edit: It works in my preliminary testing. Now to try to go live...

    cr3ative
    Last edited by cr3ative; 01-08-2005 at 02:34 PM.
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  8. #8
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Excellent!

    PHP Code:
    <?php
      $host 
    'i-83-67-3-25.freedom2surf.net';
      if(
    $socket fsockopen($host404$errno$errstr30)) {
        echo 
    'Serberus is online!';
        
    fclose($socket);
      } else {
        echo 
    'Serberus appears to be offline.';
    }
    ?>
    This example works, I've uploaded it at www.gerryhyh.f2s.com/paul/serberus.php - the only changes I had to make were to change the port to 404 (which serberus uses).

    Thanks very much!
    cr3ative
    Last edited by cr3ative; 01-08-2005 at 02:41 PM.
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

  9. #9
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by cr3ative
    Thanks very much!
    You're welcome.

    Mike

Bookmarks

Posting Permissions

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