ob_start

by Rekha 2009-11-13 11:13:02

ob_start():

This function will turn output buffering on. While output buffering is active no output is sent from the script (other than headers), instead the output is stored in an internal buffer.

The contents of this internal buffer may be copied into a string variable using ob_get_contents(). To output what is stored in the internal buffer, use ob_end_flush(). Alternatively, ob_end_clean() will silently discard the buffer contents.

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active. Just make sure that you call ob_end_flush() the appropriate number of times. If multiple output callback functions are active, output is being filtered sequentially through each of them in nesting order.

Example:
<?php
ob_start();
echo "this will work";
setcookie("test", true);

ob_end_flush();

?>


Actually, ob_start() tells PHP to start output buffering, meaning that anything you output after ob_start() wont be sent to the browser until the end of the page or ob_end() etc are reached.

So that means that once you use ob_start() and echo something out, you can still set cookies without any errors.

Tagged in:

1588
like
0
dislike
0
mail
flag

You must LOGIN to add comments