PHP Header用于頁面跳轉(zhuǎn)的注意事項(xiàng):1、location和【:】號間不能有空格,否則會出錯;2、在用header前不能有任何的輸出;3、header后的PHP代碼還會被執(zhí)行。
大觀網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,大觀網(wǎng)站設(shè)計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為大觀上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請找那個售后服務(wù)好的大觀做網(wǎng)站的公司定做!
PHP Header用于頁面跳轉(zhuǎn)的注意事項(xiàng):
下面是和asp中重定向response.redirect
的比較:
例1:
response.redirect "../test.asp" header("location:../test.php");
兩者區(qū)別:
asp的redirect
函數(shù)可以在向客戶發(fā)送頭文件后起作用.
如
<html><head></head><body> <%response.redirect "../test.asp"%> </body></html>
查是php中下例代碼會報錯:
<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ù).
例2:
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后不會再執(zhí)行后面的代碼.
而php在執(zhí)行header后,繼續(xù)執(zhí)行下面的代碼.
在這方面上php中的header重定向不如asp中的重定向.有時我們要重定向后,不能執(zhí)行后面的代碼:
一般地我們用
if(...) header("..."); else { ... }
但是我們可以簡單的用下面的方法:
if(...) { header("...");exit();}
還要注意的是,如果是用Unicode(UTF-8)編碼時也會出現(xiàn)問題,需要調(diào)整緩存設(shè)置.
<[email=%@]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="936"%> <%if Request.ServerVariables("SERVER_NAME")="s.jb51.net" then response.redirect "news/index.htm" else%> <%end if%> <script> var url = location.href; if(url.indexOf('http://www.devdao.com/')!=-1)location.href='/index/index.htm'; if(url.indexOf('http://www.knowsky.com/')!=-1)location.href='/index1/index.htm'; if(url.indexOf('http://www.google.com/')!=-1)location.href='/cn/index.asp'; if(url.indexOf('http://www.baidu.com/')!=-1)location.href='/cn/index.asp'; </script>
相關(guān)學(xué)習(xí)推薦:php編程(視頻)
本文標(biāo)題:PHPHeader用于頁面跳轉(zhuǎn)的注意事項(xiàng)有哪些
當(dāng)前網(wǎng)址:http://m.kartarina.com/article26/cpcgjg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、自適應(yīng)網(wǎng)站、外貿(mào)建站、營銷型網(wǎng)站建設(shè)、移動網(wǎng)站建設(shè)、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)