PHP 获取网页301|302真实地址

 1 function getRealURL($url){
 2     $header = get_headers($url,1);
 3     if (strpos($header[0],'301') || strpos($header[0],'302')) {
 4         if(is_array($header['Location'])) {
 5             return $header['Location'][count($header['Location'])-1];
 6         }else{
 7             return $header['Location'];
 8         }
 9     }else {
10         return $url;
11     }
12 }            
 1 function getRealURL($url){
 2     $header = get_headers($url,1);
 3     if (strpos($header[0],'301') || strpos($header[0],'302')) {
 4         if(is_array($header['Location'])) {
 5             return $header['Location'][count($header['Location'])-1];
 6         }else{
 7             return $header['Location'];
 8         }
 9     }else {
10         return $url;
11     }
12 }            

猜你喜欢

转载自www.cnblogs.com/yixin007/p/12449521.html