国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 開(kāi)發(fā) > PHP > 正文

PHP Header用于頁(yè)面跳轉(zhuǎn)要注意的幾個(gè)問(wèn)題總結(jié)

2024-05-04 23:43:48
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

在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ā)送頭文件后起作用.

<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ù).
例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.
原來(lái)在asp中執(zhí)行redirect后不會(huì)再執(zhí)行后面的代碼.
而php在執(zhí)行header后,繼續(xù)執(zhí)行下面的代碼.
在這方面上php中的header重定向不如asp中的重定向.有時(shí)我們要重定向后,不能執(zhí)行后面的代碼:
一般地我們用
if(...)
header("...");
else
{
...
}
但是我們可以簡(jiǎn)單的用下面的方法:
if(...)
{ header("...");exit();}
還要注意的是,如果是用Unicode(UTF-8)編碼時(shí)也會(huì)出現(xiàn)問(wèn)題,需要調(diào)整緩存設(shè)置.
<[email=%@]%@LANGUAGE="VBSCRIPT[/email]" CODEPAGE="936"%>
<%if Request.ServerVariables("SERVER_NAME")="m.vevb.com" then
response.redirect "news/index.htm"
else%>
<%end if%>
<script>
var url = location.href;
if(url.indexOf('http://m.survivalescaperooms.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)教程知識(shí)閱讀請(qǐng)移步到PHP教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桦南县| 嘉黎县| 高阳县| 吐鲁番市| 黄平县| 扬州市| 余江县| 德安县| 碌曲县| 建阳市| 张掖市| 当阳市| 兴安盟| 抚松县| 西青区| 临汾市| 惠来县| 鸡泽县| 伊金霍洛旗| 建宁县| 舞阳县| 隆安县| 子洲县| 岑溪市| 油尖旺区| 织金县| 新宾| 肥城市| 咸丰县| 姚安县| 二手房| 抚远县| 牟定县| 衡水市| 绵阳市| 临沂市| 宁都县| 沁阳市| 夏邑县| 中西区| 饶平县|