0
我試圖實現一個頭響應跟隨recursevely頭重定向。我已經實現了對第一個請求正確工作的以下內容,但是如果在頭中找到位置重定向,則get_headers不會爲重定向的位置返回任何結果。我想顯示每個頭申請的頭。PHP get_headers遞歸
這就是我所做的。
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;
}
任何想法?我有一個在線實現...如果需要看到一個工作代碼。 謝謝