« 2014年04月 | メイン | 2014年08月 »

2014年05月20日

file_get_contentsで実際に取得したURL

file_get_contentsで実際に取得したURLがほしい時
何者かは詳細は不明だが $http_response_header という便利なものが・・・

これを使って最後のlocation headerを取得すれば該当のもの取れるんじゃね?

if ($fdat = @file_get_contents($url){
//実際に取得したURLを判定する
if(@count($http_response_header)){
foreach($http_response_header as $t_header){
if(preg_match("/^Location: (https?:\/\/.*)$/i",trim($t_header),$mc)){
$url = $mc[1];
}
}
}
}



投稿者 muuming : 16:52