PHP setcookie() cannot modify header information 的解决方法
2009-01-09 00:55
821 查看
使用setcookie()函数时总是报以下错误:
Warning: Cannot modify header information - headers already sent by....
解决办法如下:
方法一:
在PHP里Cookie的使用是有一些限制的。
1、使用setcookie必须在<html>标签之前
2、使用setcookie之前,不可以使用echo输入内容
3、直到网页被加载完后,cookie才会出现
4、setcookie必须放到任何资料输出浏览器前,才送出
.....
由于上面的限制,在使用setcookie()函数时,学会遇到 "Undefined index"、"Cannot modify header information - headers already sent by"…等问题,解决办法是在输出内容之前,产生cookie,可以在程序的最上方加入函数 ob_start();
ob_start :打开输出缓冲区
函数格式:void ob_start(void)
说明:当缓冲区激活时,所有来自PHP程序的非文件头信息均不会发送,而是保存在内部缓冲区。为了输出缓冲区的内容,可以使用ob_end_flush()或flush()输出缓冲区的内容。
方法二:
解决Warning: Cannot modify header information - headers already sent by ......
前几天装了个php的大头贴系统测试,发现报错Warning: Cannot modify header information - headers already sent by ......
今天又装openads,还是出现这个问题。怒了。上网找了半天,有人说要在文件开头写上
ob_start();
失败。
后来打开 php.ini 然后把 output_buffering 设为 on 。重起appache,OK。看来这才是解决办法。
特别注意:
如果使用utf-8编码,一定要去掉UTF-8中的BOM,这都是因为utf-8编码文件含有的bom原因,而php4,5都是不支持bom的。去掉bom,可以用Notepad++打开转换一下。
Warning: Cannot modify header information - headers already sent by....
解决办法如下:
方法一:
在PHP里Cookie的使用是有一些限制的。
1、使用setcookie必须在<html>标签之前
2、使用setcookie之前,不可以使用echo输入内容
3、直到网页被加载完后,cookie才会出现
4、setcookie必须放到任何资料输出浏览器前,才送出
.....
由于上面的限制,在使用setcookie()函数时,学会遇到 "Undefined index"、"Cannot modify header information - headers already sent by"…等问题,解决办法是在输出内容之前,产生cookie,可以在程序的最上方加入函数 ob_start();
ob_start :打开输出缓冲区
函数格式:void ob_start(void)
说明:当缓冲区激活时,所有来自PHP程序的非文件头信息均不会发送,而是保存在内部缓冲区。为了输出缓冲区的内容,可以使用ob_end_flush()或flush()输出缓冲区的内容。
方法二:
解决Warning: Cannot modify header information - headers already sent by ......
前几天装了个php的大头贴系统测试,发现报错Warning: Cannot modify header information - headers already sent by ......
今天又装openads,还是出现这个问题。怒了。上网找了半天,有人说要在文件开头写上
ob_start();
失败。
后来打开 php.ini 然后把 output_buffering 设为 on 。重起appache,OK。看来这才是解决办法。
特别注意:
如果使用utf-8编码,一定要去掉UTF-8中的BOM,这都是因为utf-8编码文件含有的bom原因,而php4,5都是不支持bom的。去掉bom,可以用Notepad++打开转换一下。
您可能感兴趣的文章:
- PHP如何读取由JavaScript设置的Cookie
- php读取javascript设置的cookies的代码
- php中cookie的使用方法
- PHP setcookie设置Cookie用法(及设置无效的问题)
- PHP之COOKIE支持详解
- php cookie 登录验证示例代码
- PHP会话控制:Session与Cookie详解
- 在PHP中设置、使用、删除Cookie的解决方法
- php使用cookie实现记住登录状态
- PHP5中Cookie与 Session使用详解
- php中如何同时使用session和cookie来保存用户登录信息
- PHP与JavaScript针对Cookie的读写、交互操作方法详解
相关文章推荐
- PHP setcookie() cannot modify header information 的解决方法
- php setcookie 之 Cannot modify header information 解决方法
- PHP setcookie() 报 cannot modify header information 错误的解决方法
- PHP setcookie() 报 cannot modify header information 错误的解决方法
- PHP setcookie() cannot modify header information 的解决方法
- PHP setcookie() cannot modify header information 的解决方法
- php Cannot modify header information - headers already sent by set 解决方法
- PHP错误Warning: Cannot modify header information - headers already sent by解决方法
- php出现Cannot modify header information问题的解决方法大全
- PHP错误Warning: Cannot modify header information - headers already sent by解决方法
- php出现Cannot modify header information问题的解决方法大全
- PHP出现"Cannot modify header information"警告的解决方法
- php解决乱码问题时,出现Cannot modify header information问题的解决方法
- PHP中 header错误问题 的解决方法Cannot modify header information
- PHP错误Warning: Cannot modify header information - headers already sent by解决方法
- php出现Cannot modify header information问题的解决方法大全
- php出现Cannot modify header information问题的解决方法大全
- PHP错误Warning: Cannot modify header information - headers already sent by解决方法
- PHP经典header错误"Cannot modify header information"的解决方法(转)
- PHP提示Cannot modify header information - headers already sent by解决方法