Check if a URL exists and return code not 404(not found) with cURL PHP
By admin • Mar 24th, 2010 • Category: Web ProgrammingHere is a simple function that will do just that, determine if a website exists using PHP and cURL. It’s check http code, if http code is 404 (Not Found) it will return false.
function urlExists($url=NULL) {
if($url == NULL) return false;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode>=200 && $httpcode<300){
return true;
} else {
return false;
}
}
admin is
Email this author | All posts by admin



zineteregofe…
Download mp3 with Ernest Ranglin…
??? ???????? ??? ?????
…
Here is a simple function that will do just that, determine if a website exists using PHP and cURL…..