Home  >  Article  >  Backend Development  >  有没有办法取得file_get_contents返回页面的url

有没有办法取得file_get_contents返回页面的url

WBOY
WBOYOriginal
2016-06-13 12:04:50866browse

有没有办法获得file_get_contents返回页面的url
用file_get_contents带cookie访问某远程页面,但是该页面跳转到另一页面,现在问题是能否获得跳转后页面的url?我知道用get_headers是可以获得cookie等头信息的,但是如何获得url呢?
------解决方案--------------------
file_get_contents 会根据 http 头的指示自动跳转到新的目标 url
如果目标 url 有跳转,则在 get_headers 的结果中有 Location 项。
且 get_headers 也会跟踪到最终目标,于是最后的 Location 项的值就是你要的了

<br />$a = get_headers($url, 1);<br />if(isset($a['Location'])) {<br />  $url = is_array($a['Location']) ? array_pop($a['Location']) : $a['Location'];<br />}

------解决方案--------------------
他只有一节 200,所以并没有发生 http 跳转
而是在表单接受页直接 include 了帖子页
你只能分析页面内容,找出帖子的 id
其实也很简单:找到回复的代码就可以了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn