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
2009-10-19 08:47:15
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.
2009-10-19 08:53:33
As it is now it returns and displays the page being queried, how can I do it silently?
zuk1
2009-10-19 09:06:05
Nevermind I found that option.
zuk1
2009-10-19 09:08:00