PHP setcookie() cannot modify header information 的解决方法
来源:互联网 发布:c指针例题编程 编辑:程序博客网 时间:2024/05/17 01:26
使用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++打开转换一下。
0 0
- 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问题的解决方法大全
- php出现Cannot modify header information问题的解决方法大全
- php出现Cannot modify header information问题的解决方法
- php出现Cannot modify header information问题的解决方法大全
- php出现Cannot modify header information问题的解决方法大全
- PHP出现"Cannot modify header information"警告的解决方法
- Cannot modify header information的解决方法
- "Warning: Cannot modify header information”的解决方法!
- PHP经典header错误"Cannot modify header information"的解决方法(转)
- PHP中 header错误问题 的解决方法Cannot modify header information
- PHP中 header错误问题 的解决方法Cannot modify header information
- php下遇到 Cannot modify header information 的警告
- php出现Cannot modify header information
- php出现Cannot modify header information问题
- 关于数据库索引的简介
- android:打开系统联系人界面并获取数据
- iOS触摸事件处理
- SpringMVC配置文件的补充
- 小白书训练-Andy's First Dictionary
- PHP setcookie() cannot modify header information 的解决方法
- Tomcat优化配置
- iPhone6分辨率与适配
- ConcurrentHashMap介绍
- android自动跳转到指定Activity
- CentOS安装NodeJS及Express开发
- 主要的程序开发语言以及其后续发展…
- java类型转化错误
- S3C2416睡眠后唤醒的具体细节