【问题标题】:Warning: Cannot modify header information - headers already sent when using ChromePhp.php [duplicate]警告:无法修改标头信息 - 使用 ChromePhp.php 时已发送标头 [重复]
【发布时间】:2014-11-13 13:53:30
【问题描述】:

我希望查看我的 PHP 代码,看看发生了什么来帮助我纠正一些问题。 PHP 代码用于处理来自表单的数据。我已经尝试过 Chrome Logger http://craig.is/writing/chrome-logger 但我无法让它向我发送任何消息到浏览器控制台。

我已经构建了一个简单的测试用例:

文件 ChromeLoggerTest.html

<html>
<body>
<?php include './scripts/ChromeLoggerTest.php';?>
<p>Hi from ChromeLoggerTest.html</p>
</body>
</html>

文件 ChromeLoggerTest.php

<?php
include 'ChromePhp.php';
$theDate = date("l jS \of F Y h:i:s A");
ChromePhp::log("Hello console using ChromePhp::log from ChromeLoggerTest.php.  The date is: $theDate");
ChromePhp::warn("Hello console using ChromePhp::warn from ChromeLoggerTest.php.  The date is: $theDate");
echo "<p>Hello Browser from ChromeLoggerTest.php. Welcome to my php file to test Chrome Logger.  The date is $theDate </p>";
?>

如果我在浏览器窗口中获得的浏览器地址栏中键入 ChromeLoggerTest.html:

警告:无法修改标头信息 - 标头已由第 394 行 /home/d50364/public_html/scripts/ChromePhp.php 中的 /home/d50364/public_html/ChromeLoggerTest.html:3 发送的标头

警告:无法修改标头信息 - 标头已由(输出开始于 /home/d50364/public_html/ChromeLoggerTest.html:3)在 /home/d50364/public_html/scripts/ChromePhp.php 第 394 行发送 来自 ChromeLoggerTest.php 的您好浏览器。欢迎使用我的 php 文件来测试 Chrome Logger。日期是 2014 年 11 月 13 日星期四 12:35:07 PM

来自 ChromeLoggerTest.html 的您好

控制台没有输出。如果我注释掉 PHP 文件中的 ChromePhp 行,那么错误就会消失,但我在控制台中没有得到任何输出。

如果我在浏览器窗口和浏览器控制台中获得的浏览器地址栏中键入 scripts/ChromeLoggerTest.php:

浏览器:

来自 ChromeLoggerTest.php 的你好浏览器。欢迎使用我的 php 文件来测试 Chrome Logger。日期是 2014 年 11 月 13 日星期四 12:47:13 PM

浏览器控制台:

使用 ChromeLoggerTest.php 中的 ChromePhp::log 的 Hello 控制台。日期是:2014 年 11 月 13 日星期四 12:47:13 PM 使用 ChromeLoggerTest.php 中的 ChromePhp::warn 的 Hello 控制台。日期是:2014 年 11 月 13 日星期四 12:47:13 PM

在 Stackoverflow 上阅读有关于使用 ob_start();ob_flush(); 的建议,这些都没有解决我的问题。

还有人认为该问题可能是由文件中的空格引起的。我已将它们分别编辑为一行,但这并没有解决我的问题。

我已验证文件在没有 BOM 的情况下保存。

一些相关链接:

Warning: Cannot modify header information - headers already sent by ERROR

How to fix "Headers already sent" error in PHP

https://www.geeklog.net/faqman/index.php?op=view&t=38

Setting Up ChromePhp For Wordpress Using Xampp

https://wordpress.org/support/topic/error-cannot-modify-header-information-2

https://github.com/ccampbell/chromephp/issues/15

https://github.com/ccampbell/chromephp

感谢您抽出宝贵时间阅读本文。感谢您提供任何帮助。

【问题讨论】:

  • 有:&lt;html&gt;&lt;body&gt; 是输出。

标签: php chromephp chromelogger


【解决方案1】:

将这个:&lt;?php include './scripts/ChromeLoggerTest.php';?&gt; 移动到 &lt;html&gt; 之前,因为 &lt;html&gt;new line&lt;body&gt; 是输出。

【讨论】:

  • 感谢 Iolka_bolka。事实证明,我的表单处理器 php 文件中有另一个错误,我精简的测试用例没有用,因为你观察到我的&lt;php include... 应该高于我的&lt;html&gt;,所以它保证不起作用。如果其他人收到已发送错误的标头,我建议您使用if (headers_sent()) {die("Redirect failed...........");} 来帮助定位问题。
猜你喜欢
  • 2011-01-15
  • 2011-05-09
  • 1970-01-01
  • 1970-01-01
  • 2012-03-31
  • 2013-11-24
  • 2012-07-21
  • 1970-01-01
相关资源
最近更新 更多