PHP gets 301 redirect page after jump real URL address

Source: Internet
Author: User
Tags http request win32

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
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.