php出现Cannot modify header information问题的解决方法大全
来源:互联网 发布:用友软件好学吗 编辑:程序博客网 时间:2024/03/28 17:30
我做了一个统一的出错提示函数,在函数执行里面,先处理出错的地址写入cookie以方便用户登陆以后可以直接跳转到要执行的这个页面,可是发现在服务器上测试时,竟然提示本地没有出现的错误: Warning: Cannot modify header information - headers already sent by........
这样的语句,很显然,造成这个原因是因为setcookie造成的,查了一下网上,有如下的解释: cookie本身在使用上有一些限制,例如:
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出现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问题
- PHP中 header错误问题 的解决方法Cannot modify header information
- PHP中 header错误问题 的解决方法Cannot modify header information
- php出现Cannot modify header information
- PHP setcookie() 报 cannot modify header information 错误的解决方法
- PHP setcookie() cannot modify header information 的解决方法
- PHP setcookie() 报 cannot modify header information 错误的解决方法
- Cannot modify header information的解决方法
- "Warning: Cannot modify header information”的解决方法!
- PHP经典header错误"Cannot modify header information"的解决方法(转)
- php setcookie 之 Cannot modify header information 解决方法
- wordpress在登录后台出现“Warning: Cannot modify header information - headers already sent by”的解决方法
- 问答 ——如何加强 iOS 里的列表滚动时的顺畅感?
- 两台Mysql数据库数据同步实现
- void与void*详解
- oracle中常用表和视图
- merge into 用法小结
- php出现Cannot modify header information问题的解决方法大全
- Tomcat4 单实例的Bug
- android的图片加载几种方法
- 数据库入门
- python: 常用的一些函数——sys、os等
- UVa 459 - Graph Connectivity
- android属性系统
- Oracle Database 实例关闭和启动 浅谈
- 问答——为什么就算配置很高的 Android 手机玩游戏感觉画面也没有 iPhone 流畅,而且触屏感觉比较迟钝?