0
$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.

Maro
  • 1
  • 1

3 Answers3

3

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

Or use curl_getinfo() with option CURLINFO_EFFECTIVE_URL.

scaryzet
  • 923
  • 4
  • 9
1
curl_getinfo($curl, CURLINFO_EFFECTIVE_URL);
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
1

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'];
gok
  • 1,137
  • 1
  • 9
  • 30