Works/Doesn't work

5 messages Options
Embed this post
Permalink
Chris () Works/Doesn't work
Reply Threaded More More options
Print post
Permalink
Why is it that

<?php

        include_once('FirePHPCore/fb.php');
        ob_start();
        $firephpoptions = array('maxObjectDepth' => 10,'maxArrayDepth' => 20,'useNativeJsonEncode' => FALSE,'includeLineNumbers' => TRUE);
        FB::setOptions($firephpoptions);
        FB::setEnabled(TRUE); // Disable on production server - otherwise it's a security risk
        FB::info("Firebug ready to go!");
?>

works but

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <title>Firebug Test</title>
        </head>
        <body>
                <?php
                        include_once('FirePHPCore/fb.php');
                        ob_start();
                        $firephpoptions = array('maxObjectDepth' => 10,'maxArrayDepth' => 20,'useNativeJsonEncode' => FALSE,'includeLineNumbers' => TRUE);
                        FB::setOptions($firephpoptions);
                        FB::setEnabled(TRUE); // Disable on production server - otherwise it's a security risk
                        FB::info("Firebug ready to go!");
                ?>
        </body>
</html>

throws the error...

PHP Fatal error:  Uncaught exception 'Exception' with message 'Headers already sent in /Applications/MAMP/htdocs/rssscraper/svn/index copy.php on line 9. Cannot send log data to FirePHP. You must have Output Buffering enabled via ob_start() or output_buffering ini directive.' in /Applications/MAMP/includes/FirePHPCore/FirePHP.class.php:950
Christoph Dorn () Re: Works/Doesn't work
Reply Threaded More More options
Print post
Permalink
Try this:

<?php
  include_once('FirePHPCore/fb.php');
  ob_start();
  $firephpoptions = array('maxObjectDepth' => 10,'maxArrayDepth' => 20,'useNativeJsonEncode' => FALSE,'includeLineNumbers' => TRUE);
  FB::setOptions($firephpoptions);
  FB::setEnabled(TRUE); // Disable on production server - otherwise it's a security risk
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <head>
                <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                <title>Firebug Test</title>
        </head>
        <body>
                <?php
                        FB::info("Firebug ready to go!");
                ?>
        </body>
</html> 
Chris () Re: Works/Doesn't work
Reply Threaded More More options
Print post
Permalink
That does work, thank you Christoph, however I'm still wondering why it behaves that way? Why does the php need to be first and not embedded in HTML?

It's not a complaint, just a need to learn something from this.

Thanks again Christoph.
Danny () Re: Works/Doesn't work
Reply Threaded More More options
Print post
Permalink
It has to be done this way because if the HTML appears before output buffering is started with ob_start(), the code appearing before ob_start() will be sent to the browser right away, and once data has been sent to the browser, firebug cannot send data in the headers.  If you at least turn on output buffering, you can then throw in html code before your actual FirePHP call, because that html will be buffered
Chris () Re: Works/Doesn't work
Reply Threaded More More options
Print post
Permalink
Awesome. Thank you Danny.