Last active
February 20, 2016 22:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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