【PHP】短縮URLなどのリダイレクト先のURLを取得する関数

短縮URLなどのリダイレクト先のURLを取得する関数です。

ソースコードは以下のとおりです。

<?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;
}
}

コメントする

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

This site uses Akismet to reduce spam. Learn how your comment data is processed.