PHP get pages 301 | 302 real address

 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 }            

 

Guess you like

Origin www.cnblogs.com/yixin007/p/12449521.html