返回重定向网址的cURL查询在每次出现时都不起作用

时间:2016-02-04 18:12:48

标签: php curl

我正在尝试从网址中获取重定向的网址。为此,我使用了PHP的cURL函数。问题有时它有时会起作用而不是。这是一个非常奇怪的问题,我无法弄清楚它的根源。

$urlt='http://idealo.fr/go/511632138.html?categoryId=12313&pos=1&price=1459.95&productid=4583512&sid=26246&type=offer';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $urlt);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // Must be set to true so that PHP follows any "Location:" header
curl_setopt($ch, CURLOPT_TIMEOUT, 8);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$a = curl_exec($ch); // $a will contain all headers

$urnt = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // This is what you need, it will return you the last effective URL
curl_close($ch);
echo $urnt."<b>1st one</b><br />";

有时会返回确切的重定向网址,有时会返回基本网址。任何人都可以告诉我这背后的确切原因吗?

0 个答案:

没有答案
相关问题