Results 1 to 7 of 7

Thread: Online/Offline script help

  1. #1
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Online/Offline script help

    I want a simple php script to show if a website is offline or online.. however, i dont want it to show
    Code:
    Warning: file_get_contents( http://www.svyt.com/proxy.html) [function.file-get-contents]: failed to open stream: No such file or directory in /home/user/public_html/proxy/status.php on line 6
    I just want it to show:
    Offline
    heres my code:
    PHP Code:
    <?php if(strpos(file_get_contents(' http://www.svyt.com/proxy.html'), 'advanced') !== false)
      echo(
    '<font color="green">Online</font>');
    else
      echo(
    '<font color="red">Offline</font>'); ?>
    Note: svyt.com/proxy.html should contain the text advanced - no need to change any part of that.
    Last edited by cursed; 12-17-2006 at 05:08 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    @file_get_contents(' ht.......

    The @ symbol suppresses errors.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    That's a rather inefficient way of doing it. The simplest would be to just connect to the remote server:
    Code:
    <?php
      $online = false;
      if($f = fsockopen('svyt.com', 80)) {
        $online = true;
        fclose($f);
      }
    ?>
    However, this won't catch if the server is up but the site not functioning. You could use an HEAD request for that:
    Code:
    <?php
      $online = false;
      if($f = fsockopen('svyt.com', 80)) {
        $request = <<<END
    HEAD /proxy.html HTTP/1.1
    Host: www.svyt.com
    Connection: Close
    
    END;
        fwrite($f, $request);
        $response = '';
        while(!feof($f) && strpos($response, "\n") === false)
          $response .= fread($f, 1);
        $response = explode(' ', $response);
        $response = $response[1];
        if($reponse[0] < 4 && $reponse[0] > 1)
          $online = true;
        fclose($f);
      }
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  4. #4
    Join Date
    Aug 2006
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks, djr33, it worked perfectly.
    Twey, ill try your idea later, would it work if there was a custom 404 page? or a 404 page got redirected into a different page?

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Indeed.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I have Something similar, except i use an Iframe that points to a text file on my server.

    too Bad freewebs doesn't support php.
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Freewebs is just evil. There really are better free hosts out there
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •