如何获取返回的页面的url? [英] How get the url of the returned page?

查看:192
本文介绍了如何获取返回的页面的url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ curl = curl_init(); 
curl_setopt($ curl,CURLOPT_URL,'http://foo.com');
curl_setopt($ curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ curl,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ curl,CURLOPT_TIMEOUT,30);
curl_setopt($ curl,CURLOPT_USERAGENT,Mozilla / 5.0(Windows; U; Windows NT 5.1; pl; rv:1.9.2)Gecko / 20100115 Firefox / 3.6);
$ page = curl_exec($ curl);

现在网站foo.com发送不同的重定向,我不知道页面是什么$页面变量,foo.com/bar.php或foo.com/baz.php或其他。
我的问题是如何获取$ page变量中的页面的URL。



谢谢。

解决方案

将选项CURLOPT_HEADER设置为1并解析返回的头。



或者使用curl_getinfo >

$curl = curl_init();
 curl_setopt($curl, CURLOPT_URL, 'http://foo.com');
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($curl, CURLOPT_TIMEOUT, 30);
 curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.2) Gecko/20100115 Firefox/3.6");
 $page = curl_exec($curl);

Now the site foo.com sends different redrects and I don't know what a page is inside $page variable, foo.com/bar.php or foo.com/baz.php or other. My question is how get the url of the page inside $page variable.

Thanks.

解决方案

Set the option CURLOPT_HEADER to 1 and parse the returned header.

Or use curl_getinfo() with option CURLINFO_EFFECTIVE_URL.

这篇关于如何获取返回的页面的url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆