Skip to content

Instantly share code, notes, and snippets.

@lgarcia
Created January 9, 2013 12:15
Show Gist options
  • Save lgarcia/4492684 to your computer and use it in GitHub Desktop.
Save lgarcia/4492684 to your computer and use it in GitHub Desktop.
Chequeo url existe en PHP / Curl también para redirects
function urlExist($url)
{
$handle = curl_init($url);
if (false === $handle)
return false;
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_FAILONERROR, true); // this works
curl_setopt($handle, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
curl_setopt($handle, CURLOPT_NOBODY, true);
curl_setopt($handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, false);
$connectable = curl_exec($handle);
curl_close($handle);
return $connectable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment