PHP cookie相关的问题
作者: 王者之剑(http://www.albertsong.com/) 日期: 2007-12-04 21:46
PHP正则表达式匹配多行
作者: 王者之剑(http://www.albertsong.com/) 日期: 2007-11-27 22:16
使用header实现PHP页面重定向
作者: 王者之剑(http://www.albertsong.com/) 日期: 2007-11-24 17:44
假设有一个带form的查询页面index.php,只有一个元素keyword
有一个显示结果的query.php
如果要在没有输入keyword的时候或者其它情况返回index.php
在query.php可以这样写
<?php
if(empty($_REQUEST['keyword'])){
header( "HTTP/1.1 301 Moved Permanently" );
header("Location: ./index.php");exit;
}
//后面再写其它内容
?>
即用header实现PHP的redirect要注意header指令的前面不能有任何其它输出。
因此还有一个地方要注意:
如果PHP文件保存为UTF-8格式,切记不要保存为带BOM的,因为在PHP看来,BOM是一个字符,并且会将这个字符输出。
如果保存为带BOM的,会出现
Warning: Cannot modify header information
有一个显示结果的query.php
如果要在没有输入keyword的时候或者其它情况返回index.php
在query.php可以这样写
<?php
if(empty($_REQUEST['keyword'])){
header( "HTTP/1.1 301 Moved Permanently" );
header("Location: ./index.php");exit;
}
//后面再写其它内容
?>
即用header实现PHP的redirect要注意header指令的前面不能有任何其它输出。
因此还有一个地方要注意:
如果PHP文件保存为UTF-8格式,切记不要保存为带BOM的,因为在PHP看来,BOM是一个字符,并且会将这个字符输出。
如果保存为带BOM的,会出现
Warning: Cannot modify header information
标签: PHP
- 1










