i wrote a simple php script to check whether the website or Ip address is online or offline. All you have to do is specify a website url or ip address and the script will return with ONLINE or OFFLINE. I used php fsockopen() to accomplish this.
/* Usage:
$status = GetServerStatus('http://domain.com',80)
or
$status = GetServerStatus('IPAddress',80)
*/
<?php
function GetServerStatus($site, $port)
{
$status = array("OFFLINE", "ONLINE");
$fp = @fsockopen($site, $port, $errno, $errstr, 2);
if (!$fp) {
return $status[0];
} else
{ return $status[1];}
}
?>
If you want to ping a server to check connectivity, you can use php ping scripts.
Similar Posts:
- Domain with WWW not resolving problem!
- DNS-Test :: Free dns checking tool script!
- Using htaccess to redirect domain without http://
- BSNL Dataone – Common Error Messages & Code Numbers
- Most Popular Open Source PHP Scripts
- PHP – How to get domain name from URL?
- Sample DNS Zone File for BIND
- 10+ Free Tools to Create Favicon
- How to secure your DNS server
- how to change hostname in linux centos?


March 5, 2009
Good script. I would just return true or false though, this way you can use the result however you want (and it’s easier to do so).
March 30, 2009
tnx for script – its just what i was looking for
October 14, 2009
thanx man really helpful
March 21, 2010
Keep in mind, not all web hosts allow fSock to connect directly to their server resulting in OFFLINE even when it is actually ONLINE. But for everyone else, it works well.
December 5, 2010
Thank You for sharing this! Looks great:)
February 20, 2011
Nice script !! Realy simple and fast!
June 11, 2011
is there anyway people can check there status.
July 5, 2011
Cool Script, exactly what I was looking for. Thanks.
August 17, 2011
I was just wondering do you know how to allow people to check their sites status.since i know simple php but im confused in how to do this.
December 30, 2011
If you simply want people to check the status of, let’s say your website, you would just have to copy this function into your php code, and when you want to use it you just have to type “echo GetServerStatus();” and it will echo out ONLINE or OFFLINE
December 9, 2011
Nice script. easy to use and works perfectly
January 25, 2012
It would be better to check for status code and return it as well.