- 相關推薦
php的header和asp中的redirect比較
想要學習PHP,那么就應該要了解清楚header和asp中的redirect比較,下面是小編為大家搜集整理出來的有關于php的header和asp中的redirect比較,希望可以幫助到大家!
asp中實現(xiàn)重定向是用response.redirect 函數(shù):
用法一例:
response.redirect "../test.asp"
php中也有類似函數(shù):header
用法一例:
header("location:../test.php");
但是兩者是有區(qū)別的.
asp的redirect函數(shù)可以在向客戶發(fā)送頭文件后起作用.
如
<%response.redirect>
查是php中下例代碼會報錯:
<?
header("location:../test.php");
?>
只能這樣:
<?
header("location:../test.php");
?>
...
即header函數(shù)之前不能向客戶發(fā)送任何數(shù)據.
再看下面一例:
asp中
<%
response.redirect "../a.asp"
response.redirect "../b.asp"
%>
結果是重定向a.asp文件.
php呢?
<?
header("location:../a.php");
header("location:../b.php");
?>
我們發(fā)現(xiàn)它重定向b.php.
原來在asp中執(zhí)行redirect后不會再執(zhí)行后面的代碼.
而php在執(zhí)行header后,繼續(xù)執(zhí)行下面的代碼.
在這方面上php中的header重定向不如asp中的重定向.有時我們要重定向后,不能執(zhí)行后面的代碼:
一般地我們用
if(...)
header("...");
else
{
...
}
但是我們可以簡單的用下面的方法:
if(...)
{ header("...");break;}
【php的header和asp中的redirect比較】相關文章:
什么是PHP PHP與ASP比較03-11
ASP、JSP、PHP三種技術比較05-30
asp與php的區(qū)別01-26
PHP與ASP哪個優(yōu)秀01-25
PHP與ASP的分析對比02-27
PHP中php://input和$-POST的區(qū)別03-27
PHP利用header跳轉失效的解決方法04-23