Output Buffering
An interesting new feature in version 4 of PHP is output control. Output control (or output buffering) allows you to write and execute your scripts as normal but send data to the Web browser only at select points. The main benefit of this system is that you can call the header(), setcookie(), and session_start() functions at nearly any spot in your script without concern for the headers already sent error messages.
To begin output buffering, use the ob_start() function. Once you call it, every echo(), print(), and similar function will send data to a memory buffer rather than the Web browser. Conversely, HTTP calls (like header() and setcookie()) will not be buffered and will operate as usual.
At the conclusion of the script, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access