Never been to DZone Snippets before?

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

Cannot modify header information - headers already sent by FIX (See related posts)

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.
<?php
ob_start();

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

ob_end_flush();
exit;
?>

Comments on this post

logankoester posts on Sep 10, 2006 at 21:07
That's a cool trick. I'm not sure if I'll ever have to use it, but thanks :)
davedavis posts on Sep 27, 2006 at 11:48
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.
dezmarie posts on Jul 14, 2007 at 20:35
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.

You need to create an account or log in to post comments to this site.


Click here to browse all 4861 code snippets

Related Posts