I'm trying to implement a header response to follow recursevely headers redirects. I've implemented the following which works correctly for the first request, but if a location redirect is found in the header, the get_headers do not return any result for the redirected location. I would like to display the header for each header request.
This is what I have done.
function redirectURL($domain) {
$newLocation = '';
$domain = str_replace("\r", "", $domain);
$headers=get_headers($domain);
echo "<ul class='list-group' >";
print "<li class='list-group-item'>".$domain. "</li>";
foreach($headers as $k=>$v){
print "<li class='list-group-item'>".$k . ": " . $v . "</li>";
if(strstr($v, 'Location')){
$location = explode(":",$v);
$newLocation = $location[1].":".$location[2];
}
}
echo "</ul>";
if($newLocation != $domainName && $newLocation != ''){
redirectURL($newLocation);
}
unset($headers);
return true;
}
Any idea? I've a online implementation ... if need to see a working code. Thank you