note 109088 added to function.ob-start

From: Date: Tue, 19 Jun 2012 19:26:43 +0000
Subject: note 109088 added to function.ob-start
Groups: php.notes 
Request: Send a blank email to php-notes+get-188706@lists.php.net to get a copy of this message
I think it's worth noting that while you can't call any output functions such as echo or print from within a callback function, you can still send headers (presumably including cookies, haven't checked). Of course this only works in the first callback, like so: <?php function myCallback($buffer, $flags) { if ($flags & PHP_OUTPUT_HANDLER_START) { header('Server: LastMinuteHeaderServer'); } } ob_start('myCallback'); echo "Hello World!"; ob_end_flush(); ?> Not the most inspiring example, but in this case the code is able to sneak a last-minute header in before the headers part of the response is sent. This can be handy if you want to avoid replacing header values that are uncertain. For example if your code may return an image, but you don't want to set content type until you're sure that the image can be sent successfully, you can use the callback to leave the decision right until the very last moment, by which point you're hopefully sure of what's being sent in the HTTP body. ---- Server IP: 94.76.225.145 Probable Submitter: 77.101.25.130 ---- Manual Page -- http://www.php.net/manual/en/function.ob-start.php Edit -- https://master.php.net/note/edit/109088 Del: integrated -- https://master.php.net/note/delete/109088/integrated Del: useless -- https://master.php.net/note/delete/109088/useless Del: bad code -- https://master.php.net/note/delete/109088/bad+code Del: spam -- https://master.php.net/note/delete/109088/spam Del: non-english -- https://master.php.net/note/delete/109088/non-english Del: in docs -- https://master.php.net/note/delete/109088/in+docs Del: other reasons-- https://master.php.net/note/delete/109088 Reject -- https://master.php.net/note/reject/109088 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188706) next »