Cannot modify header information问题的解决方法【新浪云经常遇到的错误】
我做了一个统一的出错提示函数,在函数执行里面,先处理出错的地址写入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了
解决完毕!
解决方法二:
查找网上解决此问题的方法多是一样的,不过今天又遇到了这样的问题。试过之后发现可行:
找到php.ini 这个配置文件,然后查找一项:output_buffering将其值由原来的off改为on,重新启动Apache就ok了。
PS:有时,你再SAE建立php应用的时候,如果你的跳转以及setcookie不被支持,那么也会出现这种情况。需要遵循SAE开发文档规范。
Cannot modify header information问题的解决方法【新浪云经常遇到的错误】的更多相关文章
- php解决乱码问题时,出现Cannot modify header information问题的解决方法
设置页面编码使用: header("Content-Type:text/html;charset=utf-8"); 会出现:Cannot modify header informa ...
- PHP出现Cannot modify header information问题的解决方法
在C盘的WINDOWS中找到php.ini 这个配置文件,然后查找一项:output_buffering将其值由原来的off改为on,重新启动Apache就ok了.
- 阿里云服务器出现Warning: Cannot modify header information - headers already sent by (output started at 问题的解决方法
阿里云服务器出现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解决方法,需要的朋友可以参考下 今天在 ...
- PHP提示Cannot modify header information - headers already sent by解决方法
PHP提示Cannot modify header information - headers already sent by解决方法 因为 header();发送头之前不能有任何输出,空格也不行, ...
- PHP:Cannot modify header information - headers already sent by错误的解决方案
<?php ob_start();setcookie("username","test",time()+3600);echo "the user ...
- 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 ...
- 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 ...
- (转)PHP5使用cookie时报错 cannot modify header information - headers already sent by (......)
转自:http://blog.csdn.net/buyingfei8888/article/details/8899797 运行有警告Warning: Cannot modify header inf ...
随机推荐
- DevExpress之XtraReport 学习
XtraReport 一.基本概念: XtraReports 中的每个报表都由 XtraRepot 类的一个实例表示,或者由该类的子类来表示(这种情况更常见). 因此,每个报表都作为带区的容器使用,而 ...
- html 1.0 鼠标放上去会亮 onmouseover onmouseout 以及this标签的使用
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Spring Boot实践——基础和常用配置
借鉴:https://blog.csdn.net/j903829182/article/details/74906948 一.Spring Boot 启动注解说明 @SpringBootApplica ...
- 【319】Python 通过 Twilio 发短信
参考:python利用twilio模块给自己发短信 参考:使用python实现往手机发短信(基于twilio) 步骤如下: 登录 Twilio 网站注册,貌似需要***,包括用户名.密码.手机号.项目 ...
- angular性能优化心得
原文出处 脏数据检查 != 轮询检查更新 谈起angular的脏检查机制(dirty-checking), 常见的误解就是认为: ng是定时轮询去检查model是否变更.其实,ng只有在指定事件触发后 ...
- JavaScript中call,apply,bind方法
why?call,apply,bind干什么的?为什么要学这个? 一般用来指定this的环境,在没有学之前,通常会有这些问题. var a = { user:"追梦子", fn:f ...
- ArcEngine调用GP里的Merge工具传参问题
Merge工具inputs参数形式与Python中不同: string startLayerPath= cpj.TempWs.PathName + @"\" + datasetNa ...
- Win10 Notebook
E:\Perl\site\bin;E:\Perl\bin;C:\Program Files\Microsoft MPI\Bin\;C:\ProgramData\Oracle\Java\javapath ...
- Java程序设计17——多线程-Part-C
11 使用管道流 前面介绍的两种方式与其称为线程之间的通信,还不如称为线程之间协调运行的控制策略.如果需要在两条线程之间进行更多的信息交互,则可以考虑使用管道流进行通信. 管道流有3中存在形式:Pip ...
- Android 4.0关于开机启动服务
针对使用App应用管理强制停止的App,重启系统后不能收到开机启动, 需要运行一次后,在下次再启动时,才可以正确收到.