Home  >  Article  >  Backend Development  >  How to get the real address after jump in php

How to get the real address after jump in php

藏色散人
藏色散人Original
2020-07-06 10:32:313544browse

php method to obtain the jump address: first create a PHP sample code file; then obtain a short address; then obtain the header information through the "get_headers()" function; and finally analyze the jump address. .

How to get the real address after jump in php

PHP gets the real address after the jump

After getting a short connection, you need to convert the short connection into For the 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 address:

$url = 'http://t.cn/h5mwx';
 $headers = get_headers($url, TRUE);
print_r($headers);
//输出跳转到的网址
echo $headers['Location'];

Result:

Array
(
    [0] => HTTP/1.1 302 Found
    [Date] => Array
        (
            [0] => Mon, 24 Jun 2019 09:35:18 GMT
            [1] => Mon, 24 Jun 2019 09:35:18 GMT
        )
    [Content-Type] => Array
        (
            [0] => text/html;charset=UTF-8
            [1] => text/html
        )
    [Content-Length] => Array
        (
            [0] => 202
            [1] => 14615
        )
    [Connection] => close
    [Set-Cookie] => Array
        (
            [0] => aliyungf_tc=AQAAAAT06182sQMAe4N7dySC5VJrv03L; Path=/; HttpOnly
            [1] => BAIDUID=11F195A5E7DFE34FC3BF57618AF40AF5:FG=1; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
            [2] => BIDUPSID=11F195A5E7DFE34FC3BF57618AF40AF5; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
            [3] => PSTM=1561368918; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.com
        )
    [Server] => Array
        (
            [0] => nginx
            [1] => BWS/1.1
        )
    [Location] => http://www.baidu.com
    [1] => HTTP/1.0 200 OK
    [Accept-Ranges] => bytes
    [Cache-Control] => no-cache
    [Etag] => "5d0888c3-3917"
    [Last-Modified] => Tue, 18 Jun 2019 06:46:27 GMT
    [P3p] => CP=" OTI DSP COR IVA OUR IND COM "
    [Pragma] => no-cache
    [Vary] => Accept-Encoding
    [X-Ua-Compatible] => IE=Edge,chrome=1
)
http://www.baidu.com

For a lot of related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to get the real address after jump in php. For more information, please follow other related articles on the PHP Chinese website!

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