本问题已经有最佳答案,请猛点这里访问。
我希望浏览一下我的PHP代码,看看会发生什么情况来帮助我纠正一些问题。 PHP代码用于处理表单中的数据。我已经尝试过Chrome Logger http://craig.is/writing/chrome-logger,但是无法将其发送给浏览器consloe。
我建立了一个简单的测试用例:
文件ChromeLoggerTest.html
Hi from ChromeLoggerTest.html
文件ChromeLoggerTest.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"
Hello Browser from ChromeLoggerTest.php. Welcome to my php file to test Chrome Logger. The date is $theDate
?>
如果在浏览器地址栏中输入ChromeLoggerTest.html,则会在浏览器窗口中获得:
Warning: Cannot modify header information - headers already sent by (output started at /home/d50364/public_html/ChromeLoggerTest.html:3) in /home/d50364/public_html/scripts/ChromePhp.php on line 394
Warning: Cannot modify header information - headers already sent by (output started at /home/d50364/public_html/ChromeLoggerTest.html:3) in /home/d50364/public_html/scripts/ChromePhp.php on line 394
Hello Browser from ChromeLoggerTest.php. Welcome to my php file to test Chrome Logger. The date is Thursday 13th of November 2014 12:35:07 PM
Hi from ChromeLoggerTest.html
控制台中没有输出。如果我注释掉PHP文件中的ChromePhp行,则错误消失了,但控制台中没有任何输出。
如果在brwoser地址栏中键入scripts / ChromeLoggerTest.php,则会在浏览器窗口和浏览器控制台中获得:
浏览器:
Hello Browser from ChromeLoggerTest.php. Welcome to my php file to test Chrome Logger. The date is Thursday 13th of November 2014 12:47:13 PM
浏览器控制台:
Hello console using ChromePhp::log from ChromeLoggerTest.php. The date is: Thursday 13th of November 2014 12:47:13 PM
Hello console using ChromePhp::warn from ChromeLoggerTest.php. The date is: Thursday 13th of November 2014 12:47:13 PM
阅读Stackoverflow上有关使用ob_start()的建议;和ob_flush();这些都没有解决我的问题。
还建议该问题可能是由文件中的空格引起的。我已经将它们分别编辑为一行,但这并不能解决我的问题。
我已经确认文件是没有BOM保存的。
一些相关链接:
警告:无法修改标头信息-错误已发送标头
如何修复PHP中的"标头已发送"错误
https://www.geeklog.net/faqman/index.php?op=view&t=38
使用Xampp为Chromepress设置ChromePhp
https://wordpress.org/support/topic/error-cannot-modify-header-information-2
https://github.com/ccampbell/chromephp/issues/15
https://github.com/ccampbell/chromephp
感谢您抽出时间来阅读。非常感谢您提供的任何帮助。
有:和是输出。
将其移动到之前的,因为,new line和是输出。
谢谢Iolka_bolka。 事实证明,我的表单处理器php文件中还有另一个错误,我瘦下来的测试用例没有用,因为由于您观察到我的应该在我的以上,因此保证了它无法工作。 如果其他任何人收到的标头已经发送了错误,我建议您撒上if (headers_sent()) {die("Redirect failed...........");}来帮助定位问题。