Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

follow redirects with curl in php

Tags:

php

curl

I know that using cURL i can see the destination URL, pointing cURL to URL having CURLOPT_FOLLOWLOCATION = true.

Example :

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "www.example1.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
$result = curl_exec($ch);
$info = curl_getinfo($ch); //Some information on the fetch
curl_close($ch);

$info will have the url of the final destination which can be www.example2.com. I hope my above understanding is correct. Please let me know if not!.

My main question is, what all type of redirection cURL will be able to know? Apache redirect, javascript redirects, form submition redirects, meta-refresh redirects!?

update Thanks for your answeres @ceejayoz and @Josso. So is there a way by which I can follow all the redirect programatically through php?

like image 595
jtanmay Avatar asked Dec 15 '10 20:12

jtanmay


1 Answers

cURL will not follow JS or meta tag redirects.

like image 147
ceejayoz Avatar answered Sep 28 '22 04:09

ceejayoz