From the course: PHP with MySQL Essential Training: 1 The Basics

Unlock the full course today

Join today to access over 24,700 courses taught by industry experts.

Output buffering

Output buffering

- [Instructor] In this chapter, we've been discussing headers and page redirection. One of the important points which has come up a few times is that it's essential that any changes to the headers come before any output to the HTML. In this movie, we'll look at that a little closer, and also learn how we can use output buffering to help us. Let me start by giving you a metaphor, for illustration. Let's imagine that our PHP code is a faucet, and that our web server is a glass. Every time our PHP code outputs some data, it goes into the glass, like drops of water. As soon as the web server receives its first drops of data, it creates the headers for the data, and they can't be changed. Once the PHP code is complete, then the web server will take the accumulated data and send it to the user's browser. Now, let's imagine a second example, where our PHP code goes not directly into the glass, but instead into another container. This container is the PHP output buffer, and it's like a…

Contents