想要學習PHP,那麼就應該要了解清楚header和asp中的redirect比較,下面是小編爲大家蒐集整理出來的有關於php的header和asp中的redirect比較,希望可以幫助到大家!
asp中實現重定向是用rect 函數:
用法一例:
rect "../"
php中也有類似函數:header
用法一例:
header("location:../");
但是兩者是有區別的.
asp的redirect函數可以在向客戶發送頭文件後起作用.
如
<%rect>
查是php中下例代碼會報錯:
<?
header("location:../");
?>
只能這樣:
<?
header("location:../");
?>
...
即header函數之前不能向客戶發送任何數據.
再看下面一例:
asp中
<%
rect "../"
rect "../"
%>
結果是重定向文件.
php呢?
<?
header("location:../");
header("location:../");
?>
我們發現它重定向.
原來在asp中執行redirect後不會再執行後面的代碼.
而php在執行header後,繼續執行下面的代碼.
在這方面上php中的header重定向不如asp中的`重定向.有時我們要重定向後,不能執行後面的代碼:
一般地我們用
if(...)
header("...");
else
{
...
}
但是我們可以簡單的用下面的方法:
if(...)
{ header("...");break;}