setcookie中Cannot modify header information-headers already sent by错误的解决方法详解
2013-05-08 00:00
756 查看
<?php setcookie("username","bu",time()+3600); echo "aaaaa"; ?>
运行有警告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) 这时就可以转码了.
相关文章推荐
- 帝国cms Warning: Cannot modify header information - headers already sent by...错误【解决方法】
- 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 的解决方法fi
- PHP错误Warning: 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错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- codeigniter 错误提示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的方法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- Cannot modify header information - headers already sent by错误解决办法
- 解决”cannot modify header information – headers already sent by”的错误
- php Cannot modify header information - headers already sent by set 解决方法
- 解决Warning: Cannot modify header information - headers already sent by的方法
- wdcp 解决Cannot modify header information - headers already sent by 警告的解决方法