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. 原來在asp中執(zhí)行redirect后不會(huì)再執(zhí)行后面的代碼. 而php在執(zhí)行header后,繼續(xù)執(zhí)行下面的代碼. 在這方面上php中的header重定向不如asp中的重定向.有時(shí)我們要重定向后,不能執(zhí)行后面的代碼:
一般地我們用 if(...) header('...'); else { ... } 但是我們可以簡單的用下面的方法: if(...) { header('...');b
reak;}
相關(guān)文章:
1. 利用ajax+php實(shí)現(xiàn)商品價(jià)格計(jì)算2. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)3. asp(vbscript)中自定義函數(shù)的默認(rèn)參數(shù)實(shí)現(xiàn)代碼4. ASP基礎(chǔ)知識(shí)VBScript基本元素講解5. asp批量添加修改刪除操作示例代碼6. php網(wǎng)絡(luò)安全中命令執(zhí)行漏洞的產(chǎn)生及本質(zhì)探究7. asp讀取xml文件和記數(shù)8. ASP.NET泛型三之使用協(xié)變和逆變實(shí)現(xiàn)類型轉(zhuǎn)換9. Ajax獲取php返回json數(shù)據(jù)動(dòng)態(tài)生成select下拉框的實(shí)例10. asp.net core項(xiàng)目授權(quán)流程詳解
