1、location和“:”號間不能有空格,否則會出錯。
2、在用header前不能有任何的輸出。
3、header後的PHP代碼還會被執行。
下面是和asp中重新導向response.redirect的比較:
例1:
response.redirect "../test.asp"
header("location:../test.php");
兩者區別:
asp的redirect函數可以在向客戶發送標頭檔後起作用.
如
<%response.redirect "../test.asp"%>
查是php中下例代碼會報錯:
header("location:../test.php");
?>
只能這樣:
header("location:../test.php");
?>
...
即header函數之前不能向客戶發送任何資料.
例2:
asp中
<%
response.redirect "../a.asp"
response.redirect "../b.asp"
%>
結果是重新導向a.asp檔案.
php呢?
header("location:../a.php");
header("location:../b.php");
?>
我們發現它重新導向b.php.
原來在asp中執行redirect後不會再執行後面的代碼.
而php在執行header後,繼續執行下面的代碼.
在這方面上php中的header重新導向不如asp中的重新導向.有時我們要重新導向後,不能執行後面的代碼:
一般地我們用
if(...)
header("...");
else
{
...
}
但是我們可以簡單的用下面的方法:
if(...)
{ header("...");exit();}
還要注意的是,如果是用Unicode(UTF-8)編碼時也會出現問題,需要調整緩衝設定.
<[email=%@]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="936"%>
<%if Request.ServerVariables("SERVER_NAME")="s.jb51.net" then
response.redirect "news/index.htm"
else%>
<%end if%>
http://www.bkjia.com/PHPjc/319488.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/319488.htmlTechArticle1、location和“:”號間不能有空格,否則會出錯。 2、在用header前不能有任何的輸出。 3、header後的PHP代碼還會被執行。 下面是和asp中重新導向...