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

PHP method to obtain the real address and response header information after the short link jumps, the jump is true_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:22:18899browse

How to get the real address and response header information of short link jump in PHP, the real jump

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:

Copy code The code is as follows:

$url = 'http://t.cn/h5mwx';
$headers = get_headers($url, TRUE);

print_r($headers);

//Output the URL to jump to
echo $headers['Location'];

Attached is the complete array:

Copy code The code is as follows:

Array
(
[0] => HTTP/1.1 302 Moved Temporarily
[Location] => http://www.baidu.com
[Content-Type] => Array
(
                                                                                                                                                                                                                                    [1] => text/html;charset=utf-8
)
[Server] => Array

(
                                                                      [0] => weibo
                                                                  [1] => BWS/1.0
)

[Content-Length] => Array

(
                                                                                            [0] => 203
                                                                                        [1] => 16424
)

[Date] => Array

(
​​​​​​[0] => ​​​​​​[1] => Thu, 12 Dec 2013 10:42:25 GMT
)

[X-Varnish] => 2893360335

[Age] => 0

[Via] => 1.1 varnish
[Connection] => Array
(
                                                    [0] => close
                                                                                                                    [1] => Close
)
)


Attachment: official documentation of get_headers function

get_headers

— Get all headers sent by the server in response to an HTTP request

Description

array 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.

Parameters

url: 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 value

Returns an index or associative array containing the headers sent by the server in response to an HTTP request, or FALSE on failure.

Usage example:


Copy code The code is as follows:
$url = 'http://www.example.com';

print_r(get_headers($url));

print_r(get_headers($url, 1));

?>


The output of the above routine is similar to:

Copy code The code is as follows:

Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Date: Sat, 29 May 2004 12:28:13 GMT
    [2] => Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [3] => Last-Modified: Wed, 08 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 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
)

php 怎获取 JS跳转的链接

test1.php
$a="text2.php";
echo "";

test.php
include_once "test1.php";
echo $a;

就是这个意思,具体没有测试。test.php通过包含test1.php页面,输出test1.php页面中的变量"test2.php"。
 

怎获取跳转后的链接(php可以解决不)

用$_SERVER['HTTP_REFERER'];和session结合使用,或者把访问的链接都放在一个数组里
 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/848803.htmlTechArticlePHP获取短链接跳转后的真实地址和响应头信息的方法,跳转的真 获取到一个短连接,需要将短连接转换成真实的网址,通过查资料,发现...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn