出现Warning: Cannot modify header information - headers already sent by ..的解决办法

这个错误的出现,原因是:

出这个错误是因为 header(‘Content-Type:text/html;charset= UTF-8‘);发送头之前不能有任何输出。

检查了下我的输出,错误信息如下:

Warning: Cannot modify header information - headers already sent by (output started at /data/home/qxu1084910324/htdocs/bw_feature.php:1) in /data/home/qxu1084910324/htdocs/_inc.php on line 2

错误输出之前有一个<br></br>对,不知道从哪里出来的,一起来找找问题。

尝试改过编辑器的编码规则,也对这段代码进行重写,以及排除掉js预先载入和css预先载入的问题,然后将meta中对文档mime的指定删除排查,都未解决问题,最终无奈之下尝试了网友所说的可能是隐藏的输出,在火狐浏览器中也很明显的标示出隐藏输出的br对,果断将这段代码粘贴复制到另一个新的编辑页面,保存,问题解决。

终上,问题的根源在于使用其他编辑器或者源文件中存在隐藏的标签,而header()函数前是不能有任何输出的,包括空格。

时间: 2024-08-05 15:10:35

出现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解决方法,需要的朋友可以参考下 今天在测试以下代码时遇到该错误: 复制代码代码如下: session_start();$_SESSION['username']=$username;echo "<script language='javascript'>location.href='../admin.php';</sc

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

8月5日,第一个项目即将完成,测试时,发现登录功能会出现小问题:记住密码的时候会报错 Warning: Cannot modify header information - headers already sent by (output started at 经过再三在百度上查询,终于查到错误的关键原因:[setcookie之前不可以有html标签内容].导致出现这种错误的方式有很多种,但惟独这种解释最让我理解. (因为百度知道的内容不可以复制了,只能贴出地址,有详细解释)地址[http://z

PHP程序错误Warning: Cannot modify header information - headers already sent by ....

在使用phpmywind程序时出现的问题Warning: Cannot modify header information - headers already sent by .... 检查了许久,居然是编码的问题 请将单纯的utf-8格式改为utf-8无BOM编码格式 在NOTEPAD++的格式菜单可以修改 或者其它工具的

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

一般来说在header函数前不能输出html内容,类似的还有setcookie() 和 session 函数,这些函数需要在输出流中增加消息头部信息.如果在header()执行之前有echo等语句,当后面遇到header()时,就会报出 “Warning: Cannot modify header information - headers already sent by ....”错误.就是说在这些函数的前面不能有任何文字.空行.回车等,而且最好在header()函数后加上exit()函数.例

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 removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unkno

PHP:Cannot modify header information - headers already sent by出错解决

<?php ob_start();setcookie("username","test",time()+3600);echo "the username is:".$HTTP_COOKIE_VARS["username"]."\n";echo "the username is:".$_COOKIE["username"]."\n";print

如何解决PHP 出现Warning: Cannot modify header information错误?

其实,出现这种情况一般都是因为程序修改过程中出现以下几个方面的错误操作导致: 原因一.UTF8编码和BOM冲突(最常见) 如果你登录后台出现类似Warning: Cannot modify header information – headers already sent by (output started at /www/wp-content/themes/pozhejun/function.php:1) in /www/wp-includes/pluggable.php on line 8

Cannot modify header information - headers already sent by出错的原因

<?php ob_start(); setcookie("username","送家",time()+3600); echo "the username is:".$HTTP_COOKIE_VARS["username"]."\n"; echo "the username is:".$_COOKIE["username"]."\n"; pri

Warning: Cannot modify header information原因及解决方案

相信大多数人在写PHP代码的时候,都遇到过类似"Warning: Cannot send session cookie – headers already sent-"或者"Cannot add/modify header information – headers already sent-"这样的Warning提示.下面我们就来看看发生这个Warning的原因及解决方案. 函数 header(),setcookie() 和 session 函数需要在输出流中增加