PHP获取跳转后的真实地址

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值