Typical usage and reasons for using ob start

suggest change

ob_start is especially handy when you have redirections on your page. For example, the following code won’t work:

Hello!
<?php
  header("Location: somepage.php");
?>

The error that will be given is something like: headers already sent by <xxx> on line <xxx>.

In order to fix this problem, you would write something like this at the start of your page:

<?php
  ob_start();
?>

And something like this at the end of your page:

<?php
  ob_end_flush();
?>

This stores all generated content into an output buffer, and displays it in one go. Hence, if you have any redirection calls on your page, those will trigger before any data is sent, removing the possibility of a headers already sent error occurring.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Output buffering:
* Typical usage and reasons for using ob start

Table Of Contents
2 Arrays
4 Types
10 Cookies
13 Output buffering
14 JSON
15 SOAP
17 cURL
19 XML
21 Traits
35 UTF-8
36 URLs
38 PHPDoc
41 Loops
44 Closur
72 YAML
77 Cache
78 Streams
81 PDO
82 SQLite3
83 Sockets
87 MongoDB
93 IMAP
94 Redis
95 Imagick
102 APCu
108 PSR