|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-03-14 15:21 UTC] public at asd-group dot com
I'm using output buffering with a callback specified in ob_start. I'm also using the second parameter of value 2 (callback gets called each time output occurs in the application, rather than just once when the whole output buffer is flushed). My callback always returns an empty string, telling PHP to ignore the output, however as soon as this happens (ie. first 'echo' or 'print' statement in application) headers_sent starts to return true. However the HTTP headers (and terminating blank line) cant have been sent because my own calls to header() later on (eg. to set cookies) still work. Also, due to this, any code which expects output buffering to be on, and which checks headers_sent() before sending its own headers (after doing HTML output) will break using output buffering this way. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 14:00:01 2025 UTC |
Hmm I did read and follow the notes, and the following sample script is easily extacted from my description. 4.3.2 made no difference. <?php $Html = Array(); // Output buffering callback - just buffers text and returns "" to PHP (telling it to ignore output) function PhpOutputCb ($txt) { global $Html; if ($txt != "") {$Html[] = $txt;} return ""; } // Install output buffering callback, called on each output statement (due to second parameter) // ISSUE: Second parameter should be documented ob_start('PhpOutputCb', 2); $t = "<pre>Before first output statement, headers_sent() = " . (int) headers_sent() . " </pre>\n"; echo "<html>\n". "<head>\n". "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1252\">\n". "<meta http-equiv=\"Content-Language\" content=\"en-us\">\n". "<title>Bug1</title>\n". "</head>\n". "<body>\n". $t . "\n"; // ISSUE: Why does headers_sent() now return true, even though headers should not have been sent (as no output actually sent) echo "<pre>After first output statement, headers_sent() = " . (int) headers_sent() . " </pre>\n"; echo "</body>\n". "</html>\n"; // QUESTION: If commented-in, this exit() call causes PhpOutputCb to be called with "" text - why ?? //exit(); // Turn off output buffering and physically output text which our callback buffered ob_end_clean(); foreach ($Html as $key => $val) { echo $val; } ?>