Getting the 301 status is definitely fine.
The code is as follows |
Copy Code |
function Getrealurl ($url) { $header = Get_headers ($url, 1); if ($header [0], ' strpos ') | | strpos ($header [0], ' 302 ')} { if (Is_array ($header [' Location '])) { return $header [' Location '][count ($header [' Location ']) -1]; }else{ return $header [' Location ']; } }else { return $url; } } |
Added: get_headers-Gets the server to respond to all headers sent by an HTTP request
The code is as follows |
Copy Code |
$url = ' http://111cn.net '; Print_r (Get_headers ($url)); |
Results
The code is as follows |
Copy Code |
Array ( [0] => http/1.1 Moved Permanently [1] => Date:tue, June June 2014 07:49:26 GMT [2] => server:apache/2.2.22 (Win32) php/5.2.17 [3] => location:http://www.111cn.net/ [4] => content-length:314 [5] => content-type:text/html; Charset=iso-8859-1 [6] => x-via:1.1 jszjsx60:8080 (CDN cache Server V2.0), 1.1 zb51:6 (CDN cache server V2.0) [7] => Connection:close [8] => http/1.1 OK [9] => Date:tue, June June 2014 07:49:27 GMT [A] => server:apache/2.2.22 (Win32) php/5.2.17 [One] => Last-modified:tue, June June 2014 07:41:43 GMT [of] => ETag: "7a0000002fe1a1-68a9-4fd1ce83bc0f7" [A] => accept-ranges:bytes [=>] content-length:26793 [Content-type:text/html] => [[] => x-via:1.1 jszjsx60:8080 (CDN cache Server V2.0), 1.1 zb62:5 (CDN cache server V2.0) [=>] Connection:close ) |