Skip to content

Instantly share code, notes, and snippets.

@djfm
Created February 11, 2015 08:13
Show Gist options
  • Save djfm/52f8a1ad88773f6df468 to your computer and use it in GitHub Desktop.
Save djfm/52f8a1ad88773f6df468 to your computer and use it in GitHub Desktop.
getStatusAndLocation
function getStatusAndLocation($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , true);
$headers = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$m = array();
$location = null;
if (preg_match('/^location:\s+(.*?)\s*$/im', $headers, $m)) {
$location = $m[1];
}
return [$status, $location];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment