日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
使用PHPheader進(jìn)行頁(yè)面跳轉(zhuǎn)出現(xiàn)的問(wèn)題解疑

我們?cè)谶M(jìn)行頁(yè)面跳轉(zhuǎn)的時(shí)候,通常會(huì)用到PHP header。那么如何才能正確的使用PHP header呢?我們?cè)谑褂玫倪^(guò)程中應(yīng)當(dāng)注意些什么問(wèn)題呢?#t#

成都創(chuàng)新互聯(lián)公司-云計(jì)算及IDC服務(wù)提供商,涵蓋公有云、IDC機(jī)房租用、雅安電信機(jī)房、等保安全、私有云建設(shè)等企業(yè)級(jí)互聯(lián)網(wǎng)基礎(chǔ)服務(wù),溝通電話:13518219792

在PHP中用header("location:test.php")進(jìn)行跳轉(zhuǎn)要注意以下幾點(diǎn),有助于解決一些新手經(jīng)常遇到的問(wèn)題

1、location和“:”號(hào)間不能有空格,否則會(huì)出錯(cuò)。
2、在用header前不能有任何的輸出。
3、header后的PHP代碼還會(huì)被執(zhí)行。

下面是和asp中重定向response.redirect的比較:

例1:

response.redirect "../test.asp"
header("location:../test.php");

兩者區(qū)別:

asp的redirect函數(shù)可以在向客戶發(fā)送頭文件后起作用.

 
 
 
  1. < html>< head>< /head>< body>
  2. < %response.redirect "../test.asp"%>
  3. < /body>< /html>

查是php中下例代碼會(huì)報(bào)錯(cuò):

 
 
 
  1. < html>< head>< /head>< body>
  2. header("location:../test.php");
  3. ?>
  4. < /body>< /html>
  5. 只能這樣:
  6. < ? 
  7. header("location:../test.php");
  8. ?>
  9. < html>< head>< /head>< body>...< /body>< /html>

即PHP header之前不能向客戶發(fā)送任何數(shù)據(jù).
例2:

asp中

 
 
 
  1. < html>< head>< /head>< body>
  2. <%
  3. response.redirect "../a.asp"
  4. response.redirect "../b.asp"
  5. %>
  6. < /body>< /html>
  7. 結(jié)果是重定向a.asp文件.
  8. php呢?
  9. < ?
  10. header("location:../a.php");
  11. header("location:../b.php");
  12. ?>
  13. < 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í)行后面的代碼:
一般地我們用

 
 
 
  1. if(...)
  2. header("...");
  3. else
  4. {
  5. ...
  6. }

但是我們可以簡(jiǎn)單的用下面的PHP header方法:

 
 
 
  1. if(...)
  2. { header("...");exit();}

還要注意的是,如果是用Unicode(UTF-8)編碼時(shí)也會(huì)出現(xiàn)問(wèn)題,需要調(diào)整PHP header的緩存設(shè)置.

 
 
 
  1. < [email=%@]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="936"%>
  2. < %if Request.ServerVariables("SERVER_NAME")="s.jb51.net" then
  3. response.redirect "news/index.htm"
  4. else%>
  5. < %end if%>
  6. < script>
  7. var url = location.href;
  8. if(url.indexOf('http://www.jb51.net/')!=-1)location.href='/index/index.htm';
  9. if(url.indexOf('http://www.kanshule.com/')!=-1)location.href='/index1/index.htm';
  10. if(url.indexOf('http://www.shouji17.com/')!=-1)location.href='/cn/index.asp';
  11. if(url.indexOf('http://www.baidu.com/')!=-1)location.href='/cn/index.asp';
  12. < /script> 

以上就是在使用PHP header時(shí)應(yīng)當(dāng)注意的幾點(diǎn)問(wèn)題。


網(wǎng)站標(biāo)題:使用PHPheader進(jìn)行頁(yè)面跳轉(zhuǎn)出現(xiàn)的問(wèn)題解疑
分享鏈接:http://www.5511xx.com/article/ccidcsj.html