tags:

views:

42

answers:

1
+1  Q: 

PHP Trace Redirect

I have a database of over 10,000 URL's, however every single one of them redirects to another URL. How can I request a URL and find out it's final destination in a path of (possibly) multiple redirects?

+5  A: 

You can do it using the cURL functions:

$c = curl_init('http://original.url');
curl_setopt(CURLOPT_FOLLOWLOCATION, true);
curl_exec($c);

// Error checking here - see curl_error()

$newUrl = curl_getinfo($c, CURLINFO_EFFECTIVE_URL);

curl_close($c);
Greg
You might also want to do `curl_setopt(CURLOPT_MAXREDIRS,$n);` where $n is some reasonable number that would prevent following an unreasonalble number of redirects for a given url.
Mike A.
As it is now it returns and displays the page being queried, how can I do it silently?
zuk1
Nevermind I found that option.
zuk1