Check Site is Up or Down – PHP Script Tutorial & Download!

There are plenty of one page websites running nowadays just for checking whether any website is UP or Down. Do you believe If you have one page in your website will make you to pull some traffic?.

Here is the simple and effective PHP script to check whether a Website is currently Available or Not.

YOU CAN SEE THE DEMO OR DOWNLOAD THE SCRIPT AT THE BOTTOM OF THE PAGE

This script uses PHP CURL function, your server should be CURL enabled otherwise this script won’t work!.


<?php

if($_GET){

function SiteIsUpOrDown($url){

if (strpos($url, "https://") === false) {
$url = "https://" . $url;
}
//Validate the URL first!
if(filter_var($url,FILTER_VALIDATE_URL)){
$handle = curl_init(urldecode($url));
curl_setopt($handle,CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($handle,CURLOPT_HEADER,true);
curl_setopt($handle,CURLOPT_NOBODY,true);
curl_setopt($handle,CURLOPT_RETURNTRANSFER,true);

$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$response = curl_exec($handle);
curl_close($handle);

if ($response) {
return array(true, $url);
}else {
return array(false, $url);
}

}

}

list($result, $url) = SiteIsUpOrDown($_GET['url']);

if($result)
echo "$url is UP :)";
else
echo "$url is Down :(";

}
?>

<html>
<body>
<form action="" method="get">
Is <input type="text" name="url" /> Down or Up?
</form>
</body>
</html>

Demo Download

2 thoughts on “Check Site is Up or Down – PHP Script Tutorial & Download!

Leave a Reply

Theme: Overlay by Kaira
Agurchand