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中文网!
周杰伦快手直播首秀营销分析!转移资料已通过邮件发送-其他问题大同云服务器价格域名有什么价值?为什么许多人抢注域名?阿里云服务器怎么更改套餐内容阿里云的服务器加密能把我我这个网站页面更新的时间数据发给我吗19阿里双11如何买云服务器