Skip to content

Instantly share code, notes, and snippets.

@lkorth
Last active February 20, 2016 22:02
Show Gist options
  • Save lkorth/3899979 to your computer and use it in GitHub Desktop.
Save lkorth/3899979 to your computer and use it in GitHub Desktop.
PHP function to resolve a short URL in to its full redirected URL
<?php
function resolve_url($url) {
$headers = get_headers($url);
$headers = array_reverse($headers);
foreach($headers as $header) {
if (strpos($header, 'Location: ') === 0) {
$url = str_replace('Location: ', '', $header);
break;
}
}
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment