(转)PHP5使用cookie时报错 cannot modify header information - headers already sent by (......)
2014-01-10 20:16
323 查看
转自:/article/2739475.html
运行有警告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++打开转换一下。(我就是看了这个才解决问题的)
自己解决办法
PHP4,5 都不支持utf-8编码文件中的BOM
如果文件包含BOM,设置cookie或者session 时都会报错.
如何能快速方便的去掉文件的BOM.
推荐使用 Notepad++ 软件,非常优秀的免费软件.
1.可以在设置-->首选项-->新建 默认新建UTF-8(无BOM)
2.如果是在别处新建的php文件,在notpad++中打开如何将编码转变成 UTF-8(无BOM)
格式-->UTF-8(无BOM) 这时就可以转码了.
运行有警告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++打开转换一下。(我就是看了这个才解决问题的)
自己解决办法
PHP4,5 都不支持utf-8编码文件中的BOM
如果文件包含BOM,设置cookie或者session 时都会报错.
如何能快速方便的去掉文件的BOM.
推荐使用 Notepad++ 软件,非常优秀的免费软件.
1.可以在设置-->首选项-->新建 默认新建UTF-8(无BOM)
2.如果是在别处新建的php文件,在notpad++中打开如何将编码转变成 UTF-8(无BOM)
格式-->UTF-8(无BOM) 这时就可以转码了.
相关文章推荐
- php中使用header函数后,页面提示:Warnging: Cannot modify header information - headers already sent by 错误的的原因
- php错误"Cannot modify header information - headers already sent by"
- 关于报错:Warning: Cannot modify header information - headers already sent by (output started at
- 解决PHP Warning: Cannot modify header information - headers already sent by...
- 转载: PHP错误:Warning: Cannot modify header information - headers already sent by ...
- Warning: Cannot modify header information - headers already sent by...
- PHP错误:Warning: Cannot modify header information - headers already sent by ...
- Warning: Cannot modify header information - headers already sent by....
- PHP:Cannot modify header information - headers already sent by出错解决
- 解决Zend Studio中Cannot modify header information - headers already sent by 的方法
- Cannot modify header information - headers already sent by (output started at D:\PHP\xampp\htdocs\
- PHP错误:Warning: Cannot modify header information - headers already sent by ...
- PHP错误:Warning: Cannot modify header information - headers already sent by ...
- CI 出现“Message: Cannot modify header information - headers already sent by” 还session.php 行报错。
- Cannot modify header information - headers already sent by
- PHP错误:Warning: Cannot modify header information - headers already sent by ...
- Cannot modify header information - headers already sent by错误解决办法
- 帝国cms Warning: Cannot modify header information - headers already sent by...错误【解决方法】
- setcookie中Cannot modify header information-headers already sent by错误的解决方法详解
- php出错Warning: Cannot modify header information - headers already sent by (output started at