Cannot modify header information – headers already sent by (php header already sent error)

“Warning: Cannot modify header information – headers already sent by”

If this is one of the warnings you get,then just check your PHP File for the following.

1. This may be caused by white space before or after the opening and closing PHP tags <?php . . . ?>.

Remove them accordingly.

2. There are chances that text editor settings that causes the problem. Use a proper PHP Editor .

3. You can use output buffering to solve this . You can do this by calling ob_start() and ob_end_flush() in your script, or setting the output_buffering configuration directive on in your php.ini .

4. The headers have first letters uppercase .

For example:

Location, not location

Content-Type, not content-type or CONTENT-TYPE .

5. There must also be a colon and space, like

header(“Content-Type: text/plain”); is fine but not header(“Content-Type:text/plain”);


print "Senthil's PHP Page";

This error may also come when you print any thing before php header command .

7 . The other simple way to hide the Message is Disable the Warnings and Error messages to displayed on the PHP Page.

This can be done via

ini_set(“display_errors”, 1);

Put this on the top of the PHP Page .

Was breaking my head for few days before i could identify this.

Cannot modify header information – headers already sent by (php header already sent error)
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

One Response

  1. Lempert November 26, 2010 Reply

Leave a Reply to Lempert Cancel reply


Interesting BlogPosts to read

Podcasts for PHP Developers
Podcasts are one of the best way to keep oneself updated on the technologies and if are a PHP develo...
Free Weather APIs for your Web and Mobile Applications
This blog post will list out some of the free weather APIs for the developers to build web and mobil...
Codelobster PHP IDE - How to Install and Activate Codelobster PHP IDE ?
In my previous post , i wrote about the Codelobster PHP IDE and its features . In this blog post ...