Page 1 of 1

Check Online Status?

Posted: Tue Jan 21, 2003 1:57 pm
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

Re: Check Online Status?

Posted: Tue Jan 21, 2003 2:07 pm
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 ? :?

Posted: Tue Jan 21, 2003 2:09 pm
by InternetX
yes... :oops:

Posted: Tue Jan 21, 2003 2:39 pm
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

Posted: Tue Jan 21, 2003 2:49 pm
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... =/

Posted: Tue Jan 21, 2003 2:57 pm
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.

Posted: Tue Jan 21, 2003 3:05 pm
by InternetX
It means always that the domain doesn't exists :(
I have PHP 4.0.6 on the server...

Posted: Tue Jan 21, 2003 3:36 pm
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.

Posted: Wed Jan 22, 2003 5:48 am
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

Posted: Wed Jan 22, 2003 6:08 am
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 :)

Posted: Wed Jan 22, 2003 6:25 am
by Skywalker
no prb ;)

install new php version then ;)

Posted: Mon Jan 27, 2003 5:23 am
by m3mn0n
this is a sweet code. ;)