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

6.

<?php
print "Senthil's PHP Page";
header("Location: http://www.ginktage.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)
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.

1 Response

Leave a Reply