DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Desirae has posted 3 posts at DZone. View Full User Profile

Cannot Modify Header Information - Headers Already Sent By FIX

  • submit to reddit
        Buffers output and eliminates problem with spaces/line breaks at the beginning/end of files. Make sure to place ob_start(); before header(); is called.

header("Location: somepage.php"); //Redirect



Desirae Beberniss replied on Mon, 2006/08/28 - 12:12am

Yes, this is a quick fix which can be used until you can take the time to hunt down errant spaces or line breaks. It can work in an emergency situation.

Snippets Manager replied on Wed, 2006/08/02 - 10:38am

Thats not a fix, its a hacky patch. If you need to do this, your logic flow in inherently flawed, or your code is mal-formed (in the case of erroneous spaces). Actually fixing it is a better trick.

Logan Koester replied on Sun, 2006/09/10 - 8:05pm

That's a cool trick. I'm not sure if I'll ever have to use it, but thanks :)