RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
php如何获取跳转后的真实地址

php获取跳转地址的方法:首先创建一个PHP示例代码文件;然后获取一个短地址;接着通过“get_headers()”函数把头部信息获取到;最后分析跳转地址即可。

浈江网站建设公司创新互联,浈江网站设计制作,有大型网站制作公司丰富经验。已为浈江上千多家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的浈江做网站的公司定做!

PHP获取跳转后的真实地址

获取到一个短连接,需要将短连接转换成真实的网址,通过查资料,发现 PHP 提供了一个函数 get_headers() ,可以完成这个任务,先把 头部信息获取到,然后再分析跳转地址即可:

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

结果:

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

很多相关知识,请访问PHP中文网!
分享题目:php如何获取跳转后的真实地址
文章位置:http://scyingshan.cn/article/cpdhdh.html