1

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

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

file 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>";
?>

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.

Community
  • 1
  • 1
user1558796
  • 293
  • 4
  • 19

1 Answers1

1

Move this: <?php include './scripts/ChromeLoggerTest.php';?> before your <html> because the <html> the new line and the <body> are outputs.

vaso123
  • 12,347
  • 4
  • 34
  • 64
  • Thanks Iolka_bolka. It turns out that I had another error in my form processor php file, my slimmed down test case was useless as it was guaranteed to not work because of your observation that my ``. If anyone else is ever receiving headers already sent errors I would recommend sprinkling `if (headers_sent()) {die("Redirect failed...........");}` to help localise the problem. – user1558796 Nov 14 '14 at 20:32