PHP obtains the real address and response header information after a short link jump.

Source: Internet
Author: User
Tags varnish

PHP obtains the real address and response header information after a short link jump.

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:
Copy codeThe Code is as follows:
$ Url = 'HTTP: // t.cn/h5mwx ';
$ Headers = get_headers ($ url, TRUE );

Print_r ($ headers );

// Output the URL to jump
Echo $ headers ['location'];

Complete array:

Copy codeThe Code is 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] = & gt; BWS/1.0
)

[Content-Length] => Array
(
[0] = & gt; 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] = & gt; 2893360335
[Age] => 0
[Via] = & gt; 1.1 varnish
[Connection] => Array
(
[0] => close
[1] => Close
)
)

Appendix: Official get_headers function documentation

Get_headers-Retrieve 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 header sent by the server to respond to an HTTP request.

Parameters

Url: The target URL.

Format: If you set the optional format parameter to 1, get_headers () will parse the corresponding information and set the key name of the array.

Return Value

Returns the index or associated array containing the header sent by the server to respond to an HTTP request. If the index fails, FALSE is returned.

Example:
Copy codeThe Code is as follows:
<? Php
$ Url = 'HTTP: // www.example.com ';

Print_r (get_headers ($ url ));

Print_r (get_headers ($ url, 1 ));
?>
The output of the preceding routine is similar:
Copy codeThe 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] = & gt; 438
[Connection] => close
[Content-Type] => text/html
)


How does php get the JS jump link?

Test1.php
$ A = "text2.php ";
Echo "<script src =". $ a. "> </script> ";

Test. php
Include_once "test1.php ";
Echo $;

This is what it means. There is no test. Test. php outputs the variable "test2.php" on the test1.php page by including the test1.php page ".
 
How to get the link after the jump (php can solve it)

Use $ _ SERVER ['HTTP _ referer']; in combination with session, or put all access links in an array.
 

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.