2012-06-15 30 views
1

我使用這在所有瀏覽器上運行完美下列事項,除了IE9PHP頭不轉發IE9

$result = mysql_query("SELECT u_id, from users where (id = '$userID')",$db); 
$item = mysql_fetch_row($result); 

$how_many = mysql_num_rows($result); 

// if not a user send to reg 
if ($how_many < 1){ 
header("Location: /pages/registration"); 
} 

它根本不轉發 - 頭函數什麼都不做 - 不過,如果我改變的最後一個塊代碼是什麼,它的作品?!?!

if ($how_many < 1){ 
header("Location: /pages/registration"); 
// added echo for ie9 
echo "<br /><br /><br /><br />here i am "; 
} 

我無法理解這一切的邏輯原因,我是否錯過了什麼?

+0

你確定上面沒有空格嗎?你也刪除了,以及做你的成功檢查。 – 2012-06-15 16:06:34

+0

錯誤日誌中的任何錯誤? – ddlshack

+0

不,不對上述 - 空白將導致PHP錯誤(不能發送標題),其中沒有 –

回答

2

只要你不需要你應該exit你送出去的Location頭之後重定向後做任何更多的處理:

if ($how_many < 1){ 
    header("Location: /pages/registration"); 
    exit; 
} 
+0

是的,這當然是一個出路。但我想指出'echo'命令不會終止php進程,但仍然可以正確處理它。去搞清楚。 ) – raina77ow

1

通過退出或呼應,緩衝區被刷新網頁瀏覽器,IE9等待採取行動之前。

以下也將工作:

header('Location: /page'); 
flush(); 

我建議出口/管芯中使用的首標函數被調用,以防止被利用不必要的代碼/資源之後。