短縮URLなどのリダイレクト先のURLを取得する関数です。
ソースコードは以下のとおりです。
This file contains 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 get_location($url) | |
{ | |
$headers = get_headers($url, 1); | |
if(isset($headers['Location'])){ | |
if(is_array($headers['Location'])){ | |
return array_pop($headers['Location']); | |
}else{ | |
return $headers['Location']; | |
} | |
}else{ | |
return $url; | |
} | |
} |