PHP – Cannot modify header information headers already sent by

If you are a PHP developer and have faced the error “Warning: Cannot modify header information – headers already sent by” in your PHP website , here’s the solution for it.

How to fix “Cannot modify header information – headers already sent by” error in PHP ?

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”);

6.

<php
print "Senthil's PHP Page";
header("Location: http://www.developerpublish.com");
?>

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

error_reporting(0);
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)

    1 Comment

  1. Lempert
    November 26, 2010
    Reply

    Thank you! I knew just some of the methods you mentioned. All yours are great.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In today’s economy, layoffs have become a common occurrence. Companies may lay off employees for a variety of reasons, including...
Facebook is one of the most popular social media platforms in the world, with millions of users connecting with friends...
Temperature is a critical physical quantity that helps us determine the amount of heat present in a substance or environment....