久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

PHP Header用于頁面跳轉要注意的幾個問題總結

瀏覽:2日期:2024-02-19 09:20:44
在PHP中用header('location:test.php')進行跳轉要注意以下幾點,有助于解決一些新手經常遇到的問題1、location和“:”號間不能有空格,否則會出錯。2、在用header前不能有任何的輸出。3、header后的PHP代碼還會被執行。下面是和asp中重定向response.redirect的比較:例1:response.redirect '../test.asp'header('location:../test.php');兩者區別:asp的redirect函數可以在向客戶發送頭文件后起作用.如<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函數之前不能向客戶發送任何數據.例2:asp中<html><head></head><body><%response.redirect '../a.asp'response.redirect '../b.asp'%></body></html>結果是重定向a.asp文件.php呢?<?header('location:../a.php');header('location:../b.php');?><html><head></head><body></body></html>我們發現它重定向b.php.原來在asp中執行redirect后不會再執行后面的代碼.而php在執行header后,繼續執行下面的代碼.在這方面上php中的header重定向不如asp中的重定向.有時我們要重定向后,不能執行后面的代碼:一般地我們用if(...)header('...');else{...}但是我們可以簡單的用下面的方法:if(...){ header('...');exit();}還要注意的是,如果是用Unicode(UTF-8)編碼時也會出現問題,需要調整緩存設置.<[email=%@]%@LANGUAGE='VBSCRIPT[/email]' CODEPAGE='936'%><%if Request.ServerVariables('SERVER_NAME')='s.jb51.net' thenresponse.redirect 'news/index.htm'else%><%end if%><script>var url = location.href;if(url.indexOf('http://www.devdao.com/')!=-1)location.href='http://www.baoyu77737.com/index/index.htm';if(url.indexOf('http://www.mypchelp.cn/')!=-1)location.href='http://www.baoyu77737.com/index1/index.htm';if(url.indexOf('http://www.google.com/')!=-1)location.href='http://www.baoyu77737.com/cn/index.asp';if(url.indexOf('http://www.baidu.com/')!=-1)location.href='http://www.baoyu77737.com/cn/index.asp';</script>
標簽: PHP
主站蜘蛛池模板: 梅州市| 广河县| 房产| 邵阳市| 道真| 教育| 日喀则市| 堆龙德庆县| 金沙县| 香格里拉县| 富源县| 资中县| 罗田县| 潞城市| 民勤县| 章丘市| 长海县| 威海市| 伊通| 武宁县| 比如县| 十堰市| 南郑县| 盘锦市| 繁昌县| 霞浦县| 巫山县| 德格县| 牟定县| 乌鲁木齐市| 北票市| 墨竹工卡县| 苗栗市| 通江县| 罗甸县| 蓬安县| 永吉县| 丹棱县| 漳浦县| 清原| 聊城市|