Home >Backend Development >PHP Tutorial >PHP method to obtain the real address and response header information after the short link jumps, the jump is true_PHP tutorial
To obtain a short link, you need to convert the short link into a real URL. After checking the information, I found that PHP provides a function get_headers(), which can complete this task. First, get the header information, and then analyze the jump. Just transfer the address:
print_r($headers);
//Output the URL to jump to
echo $headers['Location'];
Attached is the complete array:
(
[0] => weibo
[1] => BWS/1.0
)
(
[0] => 203
[1] => 16424
)
(
[0] =>
[1] => Thu, 12 Dec 2013 10:42:25 GMT
)
[X-Varnish] => 2893360335
[Via] => 1.1 varnish
[Connection] => Array
(
[0] => close
[1] => Close
)
)
— Get all headers sent by the server in response to an HTTP request
Descriptionarray get_headers ( string $url [, int $format = 0 ] )
get_headers() returns an array containing the headers sent by the server in response to an HTTP request.
Parametersurl: Target URL.
format: If the optional format parameter is set to 1, get_headers() will parse the corresponding information and set the key name of the array.
Return valueReturns an index or associative array containing the headers sent by the server in response to an HTTP request, or FALSE on failure.
Usage example:
print_r(get_headers($url, 1));
?>
The output of the above routine is similar to:
Array
(
[0] => HTTP/1.1 200 OK
[Date] => Sat, 29 May 2004 12:28:14 GMT
[Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux)
[Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
[ETag] => "3f80f-1b6-3e1cb03b"
[Accept-Ranges] => bytes
[Content-Length] => 438
[Connection] => close
[Content-Type] => text/html
)
test1.php
$a="text2.php";
echo "";
test.php
include_once "test1.php";
echo $a;
就是这个意思,具体没有测试。test.php通过包含test1.php页面,输出test1.php页面中的变量"test2.php"。
用$_SERVER['HTTP_REFERER'];和session结合使用,或者把访问的链接都放在一个数组里