If you want check if site is available then you can use this function
Code function check_url($url) {
if(!filter_var($url, FILTER_VALIDATE_URL)) {
return "<span style='color: orange; font-size: 14px; font-weight: bold;'>URL provided wasn't valid</span>";
}
$ul = curl_init($url);
curl_setopt($ul, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ul, CURLOPT_HEADER, true);
curl_setopt($ul, CURLOPT_NOBODY, true);
curl_setopt($ul, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($ul);
curl_close($ul);
if ($resp)
return "<span style='color: green; font-size: 14px; font-weight: bold;'>Site seems to be up and running!</span>";
return "<span style='color: red; font-size: 14px; font-weight: bold;'>Oops nothing found, the site is either offline or the domain doesn't exist</span>";
}
Usage
Code $resp = check_url("http://www.fangree.com");
echo "<div class='resp'>".$resp."</div>";
http://www.fangree.com will give following message
Site seems to be up and running!
http://www.php-fangree.co.uk will give following message
Oops nothing found, the site is either offline or the domain doesn't exist
htp://www.php-fangree.co.uk will give following message
URL provided wasn't valid
I have this as a page on my site
http://www.dark-f..._check.php
|