cULR Library PHP : Check website status

Saturday, March 6, 2010 11:54
Posted in category CURL PHP Examples

function checkDomainLiveStatus($url)

{

$agent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";$ch=curl_init();

curl_setopt ($ch, CURLOPT_URL,$url );

curl_setopt($ch, CURLOPT_USERAGENT, $agent);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($ch,CURLOPT_VERBOSE,false);

curl_setopt($ch, CURLOPT_TIMEOUT, 5);

$page=curl_exec($ch);

//echo curl_error($ch);

$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if($httpcode>=200 && $httpcode<300) return true;

else return false;

}

if(checkDomainLiveStatus("http://www.yourdomain.com")) {

           echo "Website OK"."n";

} else { /* if website is down*/

          echo "Website DOWN";
}
  • Share/Bookmark
You can leave a response, or trackback from your own site.

3 Responses to “cULR Library PHP : Check website status”

  1. Liaseanemia says:

    March 7th, 2010 at 10:56 am

    Many thanks!

  2. Lita Bula says:

    March 8th, 2010 at 5:22 pm

    This is an interesting blog you have her but I can’t seem to find the RSS subscribe button.

  3. imran says:

    March 9th, 2010 at 10:25 am

    Please have a look at the bottom of the website, you got it ?

Leave a Reply