首頁 > 後端開發 > php教程 > 如何通过PHP得到此URL跳转后的URL

如何通过PHP得到此URL跳转后的URL

WBOY
發布: 2016-06-23 13:52:01
原創
1168 人瀏覽過

http://www.chong4.com.cn/cydb/go.php?7218_29882_22t
登入後複製

他是如何跳转的~~
如何通过PHP得到此URL跳转后的URL


回复讨论(解决方案)

如果不是在代码内跳转,估计要用socket才能抓到header

curl好像也有获取header的,你查查

估计是根据后面的变量实现跳转的

fsockopen方式获取这个页面,分析里面的Location后获得跳转地址。

$headers = get_headers('http://www.chong4.com.cn/cydb/go.php?7218_29882_22t', true);if(is_array($headers['Location'])){    $headers['Location'] = array_pop($headers['Location']);}$script = file_get_contents($headers['Location']);echo $script;
登入後複製

它最后的跳转像是JS来做的,简单的做法是你找出它的规律,提取出它的网址内容

通过 302 跳转到 'http://s.click.taobao.com/t_js?tu=http%3A%2F%2Fs.click.taobao.com%2Ft%3Fe%3DzGU34CA7K%252BPkqB07S4%252FK0CFcRfH0G7DbPkiN9MMH7EkQ%252B3KnWlM5fPrbcF5EKeNJ3Ts8ijJ4%252F77oX8O2iw1qEuhEhgaut73j9hJ3YPtNYm616DyrkK0aE1E31WN8TefmpCriY9EJ5O4JCWiRap3Rj1hfNxI2HSqhk8lK01rAylx5%252F9fHp6i%252FPRGYAGeegVo%252F%26spm%3D2014.12231445.1.0%26u%3D22t7218%26ref%3D%26et%3DjFBB1tzvZVjt5A%253D%253D
可以得到一段 js 代码
其中有 qs = location.search.split("?")[location.search.split("?").length-1].split("&");
所以需要用上述url 替换掉 location.search
执行js代码后,得到







frameBorder=0> frameBorder=0>

你可以继续跟踪那些js文件中的代码

本帖最后由 xuzuning 于 2013-01-17 13:01:04 编辑
通过 302 跳转到 'http://s.click.taobao.com/t_js?tu=http%3A%2F%2Fs.click.taobao.com%2Ft%3Fe%3DzGU34CA7K%252BPkqB07S4%252FK0CFcRfH0G7DbPki……


http://s.click.taobao.com/t_js?tu=http%3A%2F%2Fs.click.taobao.com%2Ft%3Fe%3DzGU34CA7K%252BPkqB07S4%252FK0CFcRfH0G7DbPkiN9MMH7EkQ%252B3KnWlM5fPrbcF5EKeNJ3Ts8ijJ4%252F77oX8O2iw1qEuhEhgaut73j9hJ3YPtNYm616DyrkK0aE1E31WN8TefmpCriY9EJ5O4JCWiRap3Rj1hfNxI2HSqhk8lK01rAylx5%252F9fHp6i%252FPRGYAGeegVo%252F%26spm%3D2014.12231445.1.0%26u%3D22t7218%26ref%3D%26et%3DjFBB1tzvZVjt5A%253D%253D
登入後複製

需要的就是这段,如何取得到?

$url = 'http://www.chong4.com.cn/cydb/go.php?7218_29882_22t';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, true);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);$content = curl_exec($ch);echo $content;
登入後複製
得到

HTTP/1.1 301 Moved Permanently
Server: nginx/1.0.15
Date: Thu, 17 Jan 2013 06:48:10 GMT
Content-Type: text/html
Connection: keep-alive
X-Powered-By: PHP/5.2.17
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Last-Modified: Thu, 17 Jan 2013 06:48:10 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Location: http://s.click.taobao.com/t?e=zGU34CA7K%2BPkqB07S4%2FK0CFcRfH0G7DbPkiN9MMH7EkQ%2B3KnWlM5fPrbcF5EKeNJ3Ts8ijJ4%2F77oX8O2iw1qEuhEhgaut73j9hJ3YPtNYm616DyrkK0aE1E31WN8TefmpCriY9EJ5O4JCWiRap3Rj1hfNxI2HSqhk8lK01rAylx5%2F9fHp6i%2FPRGYAGeegVo%2F&spm=2014.12231445.1.0&u=22t7218
Content-Length: 0

HTTP/1.1 302 Moved Temporarily
Server: Tengine
Date: Thu, 17 Jan 2013 06:48:22 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: close
Location:  http://s.click.taobao.com/t_js?tu=http%3A%2F%2Fs.click.taobao.com%2Ft%3Fe%3DzGU34CA7K%252BPkqB07S4%252FK0CFcRfH0G7DbPkiN9MMH7EkQ%252B3KnWlM5fPrbcF5EKeNJ3Ts8ijJ4%252F77oX8O2iw1qEuhEhgaut73j9hJ3YPtNYm616DyrkK0aE1E31WN8TefmpCriY9EJ5O4JCWiRap3Rj1hfNxI2HSqhk8lK01rAylx5%252F9fHp6i%252FPRGYAGeegVo%252F%26spm%3D2014.12231445.1.0%26u%3D22t7218%26ref%3D%26et%3DjFBB1ttOjF2GRA%253D%253D
Expires: Thu, 17 Jan 2013 06:48:22 GMT
Cache-Control: max-age=0

HTTP/1.1 200 OK
Server: Tengine
Date: Thu, 17 Jan 2013 06:48:22 GMT
Content-Type: text/html; charset=GBK
Content-Length: 2267
Last-Modified: Tue, 15 Jan 2013 01:49:17 GMT
Connection: close
Vary: Accept-Encoding
Expires: Thu, 17 Jan 2013 06:48:22 GMT
Cache-Control: max-age=0
Accept-Ranges: bytes

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">




<script> <br /> ...... <p class="sougouAnswer"> <p class="yy"> PHP code?12345678$url = 'http://www.chong4.com.cn/cydb/go.php?7218_29882_22t';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, true);curl_setopt($ch,…… <br /> HTTP/1.1 301 Moved Permanently <br /> Server: nginx/1.0.15 <br /> Date: Thu, 17 Jan 2013 06:48:10 GMT <br /> Content-Type: text/html <br /> Connection: keep-alive <br /> X-Powered-By: PHP/5.2.17 <br /> Expires: Mon, 26 Jul 1997 05:00:00 GMT <br /> Last-Modified: Thu, 17 Jan 2013 06:48:10 GMT <br /> Cache-Control: no-store, no-cache, must-revalidate <br /> Pragma: no-cache <br /> Location: http://s.click.taobao.com/t?e=zGU34CA7K%2BPkqB07S4%2FK0CFcRfH0G7DbPkiN9MMH7EkQ%2B3KnWlM5fPrbcF5EKeNJ3Ts8ijJ4%2F77oX8O2iw1qEuhEhgaut73j9hJ3YPtNYm616DyrkK0aE1E31WN8TefmpCriY9EJ5O4JCWiRap3Rj1hfNxI2HSqhk8lK01rAylx5%2F9fHp6i%2FPRGYAGeegVo%2F&spm=2014.12231445.1.0&u=22t7218 Content-Length: 0 <br /> <br /> 我只想要这段里红色那个URL~请问如何得到?正则处理吗?有更好的办法吗? <p class="sougouAnswer"> preg_match('/Location:(.*?)\n/', $content, $matches); <br /> 可以了 <p class="sougouAnswer"> <p class="yy"> PHP code?12345678$url = 'http://www.chong4.com.cn/cydb/go.php?7218_29882_22t';$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_HEADER, true);curl_setopt($ch,…… <br /> 你好,版主,再请教一下,比如下面这个链接 <br /> http://s.click.taobao.com/t?e=zGU34CA7K%2BPkqB07S4%2FK0CFcRfH0G7DbPkiN9MMH7EkQ%2B3KnWlM5fPrbcF5EKeNJ3Ts8ijJ4%2F77oX8O2iw1qEuhEhgaut73j9hJ3YPtNYm616DyrkK0aE1E31WN8TefmpCriY9EJ5O4JCWiRap3Rj1hfNxI2HSqhk8lK01rAylx5%2F9fHp6i%2FPRGYAGeegVo%2F&spm=2014.12231445.1.0&u=22t7218 <br /> 如何处理能得到他调整的URL呢? <br /> 正常浏览器打开,跳转到 <br /> http://detail.tmall.com/item.htm?id=16000826073&ali_trackid=2:mm_13376157_0_0,22t7218:1358426178_3k5_718549136&spm=2014.12231445.1.0 <br /> 我想用PHP得到这个URL,因为我要对这个URL加工下~ <p class="sougouAnswer"> 穿什么网www.chuanit.com当初也是遇到了这个问题。 </script>
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板