You can get all the headers from each request until the header is sent Locationusing this:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
$headers = curl_exec($ch);
curl_close($ch);
But then you will need to extract the information yourself, because $headers- this is only a string, not an array.
If you only need the last place, just do it curl_getinfo($ch,CURLINFO_EFFECTIVE_URL).
source
share