PHP Trace Redirect

php

Solution

You can do it using the cURL functions:

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

// Error checking here - see curl_error()

$newUrl = curl_getinfo($c, CURLINFO_EFFECTIVE_URL);

curl_close($c);

Problem

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?

Original source