php 中cookie学习 Warning: Cannot modify header information - headers already sent by错误
来源:互联网 发布:mac pro连接蓝牙耳机 编辑:程序博客网 时间:2024/05/22 03:17
参考
http://www.cnblogs.com/panjun-Donet/articles/1250405.html
http://www.jb51.net/article/14108.htm
1.呼叫setcookie的敘述必須放在<html>标签之前
2.呼叫setcookie之前,不可使用echo
3.直到網頁被重新載入後,cookie才會在程式中出現
4.setcookie函数必須在任何資料輸出至浏览器前,就先送出
5.……
基於上面這些限制,所以執行setcookie()函数时,常會碰到"Undefined index"、"Cannot modify header information - headers already sent by"…等問題,解決"Cannot modify header information - headers already sent by"这个錯誤的方法是在产生cookie前,先延缓資料输出至浏览器,因此,您可以在程式的最前方加上ob_start();这个函數。这样就可以解决 了。 如果要加上ob_start()的话,不大可行,程序都写完了,才来改这个似乎有点郁闷.. 发现提示这个错误的时候,我就在想我本地怎么没提示这个问题呢,还以为是PHP.ini配置不一样,想想又不对,都是差不多的..
于是看看后面跟的那句"output started at...."意思是在setcookie之前已经在另一处有输出了,于是找到output started at后面跟的那个文件,看到第一行是空白的,然后才是<?php 这样开始,难道会是这一行的问题吗??我本地也有这一行呢,去掉,刷新再试,呵呵,果然出在这里,不再提示warning了
解决完毕!
解决方法二:
查找网上解决此问题的方法多是一样的,不过今天又遇到了这样的问题。试过之后发现可行:
在C盘的WINDOWS中找到php.ini 这个配置文件,然后查找一项:output_buffering将其值由原来的off改为on,重新启动Apache就ok了。
我依靠解决方法二解决了上面问题。
<?php if (!empty ($_COOKIE['counter'] )){ $counter = $_COOKIE['counter']+1 ; echo "您是第".$counter."位访客了".'<br>'; } else{ $counter = 1 ; } setcookie("counter",$counter,time()+2678400);//统计一个月的访问流量啊?>
- php 中cookie学习 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"
- php错误"Cannot modify header information - headers already sent by"
- php 错误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 ...
- PHP错误: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 ......
- 解决Warning: Cannot modify header information - headers already sent by
- Warning: Cannot modify header information - headers already sent by
- 解决Warning: Cannot modify header information - headers already sent by..
- 解决【Warning: Cannot modify header information - headers already sent by....】
- Warning: Cannot modify header information - headers already sent by
- Warning: Cannot modify header information - headers already sent by
- Warning: Cannot modify header information - headers already sent by....
- Linux的工作环境-文件系统目录说明
- hdu 2282
- Excel 中 添加 复选框。
- Redis关键点(内存存储总体结构)
- YUM安装nginx,mysql,php-fpm,redis
- php 中cookie学习 Warning: Cannot modify header information - headers already sent by错误
- The Acts of the Mind
- iphone中libiconv库的作用
- 关于多线程渲染
- 2011年下半年项目“银行储蓄综合业务平台”C语言版
- Cisco Unified CallManager介绍
- 20120912,微软9月12日发布2个安全补丁
- WPF中把图片保存到数据库,并从数据库提取出来显示
- 如何让IE 8不再弹出Security Warning