tags:

views:

123

answers:

3

Is it possible for PHP to take a URL, wait for the redirects to go through, and then fetch the url of the page it's on?

A: 

see http://www.php.net/manual/en/wrappers.http.php

-j

echo
A: 

You also can use a wget / curl wrapper.

http://php.net/manual/en/book.curl.php

CodeJoust
+4  A: 
 $cr = curl_init("http://example.com"); 
 curl_setopt($cr, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($cr, CURLOPT_FOLLOWLOCATION, 1);   
 curl_exec($cr); 
 $info = curl_getinfo($cr);
 echo "url=".$info["url"];
serg
Also, to add serg's answer... you might want `curl_setopt($cr, CURLOPT_MAXREDIRS, 5);` to set the max number of redirects to allow.
brianreavis