Check Online Status?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Check Online Status?

Post by InternetX »

Hiya,

how can I with PHP test whether a side online is or offline is / does not exist?

Sorry for my english, I'm 14 and from Germany *s*

Thanks in Advance,
InX
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Re: Check Online Status?

Post by AVATAr »

InternetX wrote:how can I with PHP test whether a side online is or offline is / does not exist?
Do you mean a "site" http://www.something.com ? :?
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Post by InternetX »

yes... :oops:
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Well InX you could use the PHP function readfile() : http://www.php.net/manual/de/function.file.php (Made sure to send you to the German page)

Compare the content of the array it'll return to see if there's anything, you'll have to chack for 404 Document not found and domain name not found errors ...

If you have PHP 4.3.0 you could also use file_get_contents() : http://www.php.net/manual/de/function.f ... ntents.php
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Post by InternetX »

If I use readfile() always it shows:

Warning: readfile("http://www.moonychat.de") - Success in /home/moony/htdocs/test.php on line 3

But not more... =/
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Sorry InX I meant to write file() not readfile()... I started with readfile and then I checked the PHP manual and realized that it was file() not readfile() (hence the correct URL) but I guess I overlooked the function name I wrote right in front of the URL...

Try:

Code: Select all

if (@file("http://www.moonychat.de"))
{
	print "Yeah!";  // the page exists.
}
else
{
	print "Doh!";  // the domain name doesn't exists.
}
I just tested this further and it seems that it returns an error even if a 403 error is returned (I tried with http://www.moonychat.de/blah.html) So I think it's fair to assume that 404 errors will do the same.
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Post by InternetX »

It means always that the domain doesn't exists :(
I have PHP 4.0.6 on the server...
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Did you check the http://www.php.net/manual/en/ref.filesy ... -url-fopen and http://www.php.net/manual/en/wrappers.php pages?

Those URLs are pointe to in the Tipp box.
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Post by Skywalker »

This script works perfect, give up de url you want to check if it's online and you can even give up the port to scan, like 21,23,80 etc. so you can see witch service is online of the server....

http ftp etc.


Code: Select all

<?php

    $ip='www.demo.triv.nl';  

    $port=80; 

    $fp = fsockopen ($ip, $port, $errno, $errstr, 30); 

        if (!$fp) { 

            echo "<font color="#FF0000">img src="warning.gif"><b>System

Down</b><p>Error $errno: $errstr"; 

        } else { 

            echo "<font color="#0000c0"><img src="online.gif"><b>All

systems are stable and running.</b>"; 

        }


?>


greathings Skywalker
InternetX
Forum Newbie
Posts: 22
Joined: Tue Jan 21, 2003 1:57 pm
Location: Germany
Contact:

Post by InternetX »

Thanks, this script works on every server but not on my public server :(
I think i must have a higher PHP version than 4.0.6 :(
But Thanks for the Script :)
User avatar
Skywalker
Forum Contributor
Posts: 117
Joined: Thu Aug 29, 2002 3:33 am
Location: The Netherlands

Post by Skywalker »

no prb ;)

install new php version then ;)
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

this is a sweet code. ;)
Post Reply