note 95772 added to function.ob-end-clean
| From: | netom at elte dot hu | Date: | Thu, 21 Jan 2010 11:57:16 +0000 |
| Subject: | note 95772 added to function.ob-end-clean | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165159@lists.php.net to get a copy of this message | ||
Notice that ob_end_clean() does discard headers.
If you would like to clear the output buffer, but not the headers (because you use firephp for
example...), than this is the solution:
<?php
...
$headers = array();
if ( !headers_sent() ) {
$headers = apache_response_headers();
}
ob_end_clean();
ob_start();
if ( !empty( $headers ) ) {
foreach ( $headers as $name => $value ) {
header( "$name: $value" );
}
}
...
?>
I use it in a general exception handler in a web application, where I clear the buffer (but not the
debug-info-containing headers), and send a 500 error page with readfile().
Good PHPing,
Tamas.
----
Server IP: 92.43.200.200
Probable Submitter: 157.181.166.13
----
Manual Page -- http://www.php.net/manual/en/function.ob-end-clean.php
Edit -- https://master.php.net/note/edit/95772
Del: integrated -- https://master.php.net/note/delete/95772/integrated
Del: useless -- https://master.php.net/note/delete/95772/useless
Del: bad code -- https://master.php.net/note/delete/95772/bad+code
Del: spam -- https://master.php.net/note/delete/95772/spam
Del: non-english -- https://master.php.net/note/delete/95772/non-english
Del: in docs -- https://master.php.net/note/delete/95772/in+docs
Del: other reasons-- https://master.php.net/note/delete/95772
Reject -- https://master.php.net/note/reject/95772
Search -- https://master.php.net/manage/user-notes.php