Check URL Exists in PHP

<?php
function url_exists($url) {
    $handle   = curl_init($url);
    if (false === $handle)
    {
        return false;
    }
    curl_setopt($handle, CURLOPT_HEADER, false);
    curl_setopt($handle, CURLOPT_FAILONERROR, true);
    curl_setopt($handle, CURLOPT_NOBODY, true);
    curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
    $connectable = curl_exec($handle);
    curl_close($handle);
    return $connectable;
}

$url = 'http://insicdesigns.com/';

if(url_exists($url)){
	echo 'true';
}else{
	echo 'false';
}
?>

Output is
function url_exists($url) {
$handle = curl_init($url);
if (false === $handle)
{
return false;
}
curl_setopt($handle, CURLOPT_HEADER, false);
curl_setopt($handle, CURLOPT_FAILONERROR, true);
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$connectable = curl_exec($handle);
curl_close($handle);
return $connectable;
}

$url = 'http://insicdesigns.com/';

if(url_exists($url)){
echo '

‘;
echo ‘true’;
echo ‘

‘;
}else{
echo ‘

‘;
echo ‘false’;
echo ‘
‘;
}
?>

PG

Author: insic

Subscribe in my RSS Feed for more updates on Web Design and Development related articles. Follow me on twitter or drop a message to my inbox.

Related Post

Delicious

No comments yet... Be the first to leave a reply!

Leave a Reply