PHP和ASP中關(guān)于轉(zhuǎn)向函數(shù)的區(qū)別
asp中實(shí)現(xiàn)重定向是用response.redirect函數(shù):
用法一例: response.redirect '../test.asp'
php中也有類似函數(shù):header
用法一例: header('location:../test.php'); 但是兩者是有區(qū)別的.
asp的redirect函數(shù)可以在向客戶發(fā)送頭文件后起作用.
如 <html><head></head><body> <%response.redirect '../test.asp'%> </body></html>
查是php中下例代碼會(huì)報(bào)錯(cuò):
<html><head></head><body> <? header('location:../test.php'); ?> </body></html>
只能這樣:
<? header('location:../test.php'); ?> <html><head></head><body>...</body></html>
即header函數(shù)之前不能向客戶發(fā)送任何數(shù)據(jù).
再看下面一例:
asp中
<html><head></head><body> <% response.redirect '../a.asp' response.redirect '../b.asp' %> </body></html>
結(jié)果是重定向a.asp文件.
php呢?
<? header('location:../a.php'); header('location:../b.php'); ?> <html><head></head><body></body></html>
我們發(fā)現(xiàn)它重定向b.php. 原來(lái)在asp中執(zhí)行redirect后不會(huì)再執(zhí)行后面的代碼. 而php在執(zhí)行header后,繼續(xù)執(zhí)行下面的代碼. 在這方面上php中的header重定向不如asp中的重定向.有時(shí)我們要重定向后,不能執(zhí)行后面的代碼:
一般地我們用 if(...) header('...'); else { ... } 但是我們可以簡(jiǎn)單的用下面的方法: if(...) { header('...');b
reak;}
相關(guān)文章:
1. PHP利用COM對(duì)象訪問(wèn)SQLServer、Access2. PHP字符串中提取文件名的實(shí)例方法3. php設(shè)計(jì)模式之職責(zé)鏈模式實(shí)例分析【星際爭(zhēng)霸游戲案例】4. PHP session反序列化漏洞深入探究5. php字符串使用詳細(xì)了解6. PHP數(shù)據(jù)庫(kù)抽象層之PDO(三)——事務(wù)與自動(dòng)提交7. 阿里云服務(wù)器下安裝配置phpMyAdmin——基于CentOS 6.38. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享9. ASP.Net Core對(duì)USB攝像頭進(jìn)行截圖10. PHPMailer發(fā)送郵件功能實(shí)現(xiàn)流程
