转自:http://blog.csdn.net/buyingfei8888/article/details/8899797

运行有警告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)  这时就可以转码了.

(转)PHP5使用cookie时报错 cannot modify header information - headers already sent by (......)的更多相关文章

  1. php5.6,Ajax报错,Warning: Cannot modify header information - headers already sent in Unknown on line 0

    php5.6ajax报错 Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be remo ...

  2. php 报错 Cannot modify header information

    在用CI 开发微信公众号的时候出现下面这么个问题,网上看了一圈解决办法是:把报错的文件用editplus另存为utf-8. Severity: Warning Message: Cannot modi ...

  3. 关于报错:Warning: Cannot modify header information - headers already sent by (output started at

    8月5日,第一个项目即将完成,测试时,发现登录功能会出现小问题:记住密码的时候会报错 Warning: Cannot modify header information - headers alrea ...

  4. php有些系统会报错或提示 Cannot modify header information - headers already sent by

    Warning: Cannot modify header information - headers already sent by (output started at /home/test/do ...

  5. PHP错误Warning: Cannot modify header information - headers already sent by解决方法

    这篇文章主要介绍了PHP错误Warning: Cannot modify header information - headers already sent by解决方法,需要的朋友可以参考下 今天在 ...

  6. Warning: Cannot modify header information - headers already sent by (output started at

    一般来说在header函数前不能输出html内容,类似的还有setcookie() 和 session 函数,这些函数需要在输出流中增加消息头部信息.如果在header()执行之前有echo等语句,当 ...

  7. PHP:Cannot modify header information - headers already sent by错误的解决方案

    <?php ob_start();setcookie("username","test",time()+3600);echo "the user ...

  8. Warning: Cannot modify header information - headers already sent by ... functions_general.php on line 45

    摘自:有用到 http://blog.csdn.net/besily/article/details/5396268 PHP错误:Warning: Cannot modify header infor ...

  9. 转载: PHP错误:Warning: Cannot modify header information - headers already sent by ...

    如果在执行php程序时看到这条警告:"Warning: Cannot modify header information - headers already sent by ....&quo ...

随机推荐

  1. 使用JFinal实现使用MVC获取表单中的数据并将提示信息返回给另一jsp页面。

    1.包结构 2.我们需要对web.xml进行配置: <?xml version="1.0" encoding="UTF-8"?> <web-a ...

  2. .NET垃圾回收机制

    在.net 编程环境中,系统的资源分为托管资源和非托管资源.  对于托管的资源的回收工作,是不需要人工干预回收的,而且你也无法干预他们的回收,所能够做的只是了解.net CLR如何做这些操作.也就是说 ...

  3. CSS-解决苹果点击高亮、安卓select灰色背景(select下拉框在IOS中背景变黑、出现阴影问题)

    1.在苹果手机上,用点击事件后会出现一个高亮的阴影: 面对click事件的阴影,解决办法: *{ -webkit-tap-highlight-color: rgba(0,0,0,0); -webkit ...

  4. js验证前后密码是否一致,为什么当我输入不一致密码时,不会弹出警告啊

    <form name="form" action="#"><input type="password" id=" ...

  5. C# 一段通用的写log 日志的好程序

    public void Write(string text) { FileStream fs = new FileStream(Application.StartupPath+"/log.t ...

  6. Codeforces55D Beautiful numbers

    原题链接 虽然依旧是套模板,但是因为我太弱了,不会建状态,所以去看了题解.. 这里就直接引用我看的题解吧,写的不错的. 题解 //我的代码 #include<cstdio> #includ ...

  7. RTTI(运行时类型识别)

    运行时类型识别(Run-time type identification , RTTI),是指在只有一个指向基类的指针或引用时,确定所指对象的准确类型的操作.其常被说成是C++的四大扩展之一(其他三个 ...

  8. NC 5系自定义显示公式

    1.继承NcInnerFunction(nc.vo.pub.formulaset.function.NcInnerFunction) 在方法中引用父类方法function,并在里面写方法 @Overr ...

  9. swift 官方获取JSON 数据方法

    var url = NSURL(string: "http://www.weather.com.cn/data/sk/101120501.html") var data = NSD ...

  10. MySQL中varchar与char区别

    MySQL中varchar与char区别(转) MySQL中varchar最大长度是多少? 一. varchar存储规则: 4.0版本以下,varchar(20),指的是20字节,如果存放UTF8汉字 ...