Hi, Guest ~ Login or Register

Output Buffering

Output Buffering

Listed In PHP and MySQL » General Development — Viewing Full Tutorial
Output buffering is probably the best thing after the fifty things that come after sliced bread - ever been in a position where you have to keep everything on one page/can't be bothered to make a new page for your "at the top of the page only" code? Don't know what I'm on about? Didn't think so.

At-the-top-of-the-page-only PHP functions are:
header()
setcookie()
session_start()

And a few others that I can't be bothered to think of. This basically means they can NORMALLY only be called before any HTML output is sent to the browser.

Why this is isn't the point - how to bypass it is the aim of this tutorial.

If you're a code reader or a tutorial goer reading harder tutorials that have a lot of things going on in the code at one time, you might see the functions called ob_start(), and ob_end_flush().

What do they do then?
This pair of functions create an output buffer that isn't anything to do with the browser - YET. Think of it like this:
tutorials/buffering/diagram.gif

Remember, when you've
inished sending the buffer you MUST use ob_end_flush() to clear the buffer, otherwise your /tmp directory might get b0rked.. AND WE DON'T WANT THAT DO WE DIDDUMS LOL ROFL LMAO OMG GTFO WTF?

Thanks!

Will

Working Beta

  1. The Forums
    These are mostly functional. If you see any weird bugs, post a thread about it and an administrator will do something.
  2. Tutorial Writing
    You can now submit tutorials to the brand new management system.
  3. Tutorials Home
    View tutorials by categories and search for them here.
  4. Shoutbox
    See below. Registered users only!

Register

Newest User

Say hi to Lirette25! Lirette25 joined on Monday, 14th July.

Sponsor

Check out Next day fake id

Shoutbox