Reputation: 1
$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.
Upvotes: 0
Views: 599
Reputation: 1157
You could use curl_getinfo();
$info = curl_getinfo($curl);
print_r($info); // prints all the info array
if you want to only get the url, use:
echo $info['url'];
Upvotes: 1
Reputation: 923
Set the option CURLOPT_HEADER to 1 and parse the returned header.
Or use curl_getinfo() with option CURLINFO_EFFECTIVE_URL.
Upvotes: 3