We can use the get_headers () function to obtain the real address after the short URL jump. let's take a look at some examples I have summarized. to obtain a short connection, you need to convert the short connection to a real url. by checking the information, you can find the PH... we can use the get_headers () function to obtain the real address after the short URL jump. let's take a look at some examples I have summarized.
To obtain a short connection, you need to convert the short connection to a real url. by checking the information, we found that PHP provides a function get_headers () to complete this task, first obtain the header information, and then analyze the jump address.
The get_headers () function is used to obtain the http header. the get_headers () function of php is used to obtain all the headers sent by the server in response to an HTTP request. it is certainly no problem to obtain the 301 status.
The code is as follows:
$ Url = 'http: // dwz.cn/29uq}'; $ headers = get_headers ($ url, TRUE); print_r ($ headers ); // output the jump URL echo $ headers ['location'];
// Appendix:
Array ( [0] => HTTP/1.1 302 Moved Temporarily [Location] => http://www.phprm.com [Content-Type] => Array ( [0] => text/html;charset=UTF-8 [1] => text/html;charset=utf-8 ) [Server] => Array ( [0] => weibo [1] => BWS/1.0 ) [Content-Length] => Array ( [0] => 203 [1] => 16424 ) [Date] => Array ( [0] => Thu, 12 Dec 2013 10:42:25 GMT [1] => Thu, 12 Dec 2013 10:42:25 GMT ) [X-Varnish] => 2893360335 [Age] => 0 [Via] => 1.1 varnish [Connection] => Array ( [0] => close [1] => Close ) )
Let's take a look at the URL before getting a short URL jump. the code is as follows:
$header = get_headers($url, 1); if (strpos($header[0], '301') || strpos($header[0], '302')) { if (is_array($header['Location'])) { return $header['Location'][count($header['Location'])-1]; } else { return $header['Location']; } } else { return $url; }
Address:
Reprinted at will, but please attach the article address :-)