php獲取跳轉(zhuǎn)地址的方法:首先創(chuàng)建一個(gè)PHP示例代碼文件;然后獲取一個(gè)短地址;接著通過“get_headers()”函數(shù)把頭部信息獲取到;最后分析跳轉(zhuǎn)地址即可。
湞江網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián),湞江網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為湞江上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的湞江做網(wǎng)站的公司定做!
PHP獲取跳轉(zhuǎn)后的真實(shí)地址
獲取到一個(gè)短連接,需要將短連接轉(zhuǎn)換成真實(shí)的網(wǎng)址,通過查資料,發(fā)現(xiàn) PHP 提供了一個(gè)函數(shù) get_headers() ,可以完成這個(gè)任務(wù),先把 頭部信息獲取到,然后再分析跳轉(zhuǎn)地址即可:
$url = 'http://t.cn/h5mwx'; $headers = get_headers($url, TRUE); print_r($headers); //輸出跳轉(zhuǎn)到的網(wǎng)址 echo $headers['Location'];
結(jié)果:
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
很多相關(guān)知識(shí),請(qǐng)?jiān)L問PHP中文網(wǎng)!
當(dāng)前名稱:php如何獲取跳轉(zhuǎn)后的真實(shí)地址
網(wǎng)頁URL:http://weahome.cn/article/cpdhdh.html