Monday, 24 April 2017

Warning: Cannot modify header information - headers already sent when using ChromePhp.php




I wish to peek into my PHP code to see what is going on to help me rectify some issues. The PHP code is for processing the data from a form. I have tried Chrome Logger http://craig.is/writing/chrome-logger but I can't get it to send me any messages to the browser consloe.



I have built a simple test case:



file ChromeLoggerTest.html







Hi from ChromeLoggerTest.html






file 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

";
?>


If I type ChromeLoggerTest.html into the browser address bar I obtain in the browser window:





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




There is no output in the console. If I comment out the ChromePhp lines in the PHP file then the errors go away but I do not get any output in the console.




If I type scripts/ ChromeLoggerTest.php into the brwoser address bar I obtain in the browser window and browser console:



Browser:




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




Browser console:





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




Reading on Stackoverflow there are suggestions about using ob_start(); and ob_flush(); these have not solved my problem.



There are also suggestions that the issue might be caused by whitespace in the files. I have edited them to a single line each and this has not solved my problem.



I have verified that the files are saved without BOM.




Some relevant links:



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



Thank you for taking the time to read this. Any assistance gratefully received.


Answer



Move this: before your because the the new line and the are outputs.



No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...