PHP to get a short link after the real address and the response header information, jump to the true
Get to a short connection, need to convert the short connection to a real URL, through the search data, found that PHP provides a function get_headers (), you can complete this task, first get the header information, and then analyze the jump address can:
Copy the Code code as follows:
$url = ' http://t.cn/h5mwx ';
$headers = Get_headers ($url, TRUE);
Print_r ($headers);
The URL to which the output jumps
echo $headers [' location '];
A complete array is attached:
Copy the Code code as follows:
Array
(
[0] = http/1.1 302 Moved temporarily
[Location] = http://www.baidu.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, Dec 10:42:25 GMT
[1] = Thu, Dec 10:42:25 GMT
)
[X-varnish] = 2893360335
[Age] = 0
[Via] = 1.1 varnish
[Connection] = = Array
(
[0] + = Close
[1] + = Close
)
)
Attached: get_headers function Official document
get_headers -Get server to respond to all headers sent by an HTTP request
Description
Array get_headers (string $url [, int $format = 0])
Get_headers () returns an array that contains the headers sent by the server in response to an HTTP request.
Parameters
URL: Destination URL.
Format: If the optional format parameter is set to 1, Get_headers () parses the corresponding information and sets the key name of the array.
return value
Returns an index or associative array containing the headers sent by the server in response to an HTTP request, or FALSE if it fails.
Examples of Use:
Copy the Code code as follows:
<?php
$url = ' http://www.example.com ';
Print_r (Get_headers ($url));
Print_r (Get_headers ($url, 1));
?>
The output of the above routines is similar to the following:
Copy the Code code as follows:
Array
(
[0] = = http/1.1-OK
[1] = Date:sat, 2004 12:28:13 GMT
[2] = = server:apache/1.3.27 (Unix) (Red-hat/linux)
[3] = last-modified:wed, Jan 2003 23:11:55 GMT
[4] = ETag: "3f80f-1b6-3e1cb03b"
[5] = Accept-ranges:bytes
[6] = content-length:438
[7] = Connection:close
[8] = content-type:text/html
)
Array
(
[0] = = http/1.1-OK
[Date] + Sat, May 2004 12:28:14 GMT
[Server] = apache/1.3.27 (Unix) (Red-hat/linux)
[Last-modified] = Wed, Jan 2003 23:11:55 GMT
[ETag] = "3f80f-1b6-3e1cb03b"
[Accept-ranges] = bytes
[Content-length] = 438
[Connection] = Close
[Content-type] = text/html
)
php how to get the link to JS jump
test1.php
$a = "text2.php";
Echo "