Warning: Cannot modify header information - headers already sent by

Posted in February 8th, 2008
by peorex in How to

Warning: - headers already sent by (output started at /home/www/stonestreem.com/blog/
wp-content/themes/kassandra-1.0.0/functions.php:2) in /home/www/stonestreem.com/blog/wp-login.php on line 12

Reason:
This error comes when you print any thing before header.
To verify if this is the case look at the HTML source code generated:

  1. Load a blog page in your favorite browser
  2. Right click with your mouse
  3. Click “View Page Source” or similar option
  4. Look at the very beginning of source before the line that says:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

If there are blank lines or whatever - then this is the reason.

Look close at the error message. It says you what file generates the unwanted output and the line number where this occurs, in this case functions.php, line #2.
The next part of message says that the error comes in wp-login.php on line 12 (during login attempt). This line contains header command.
Now examine the file (in this case functions.php) for code that generated the unwanted output. This code may look like this:

<?php
php code1 here
?>

// The blank line above this, this line and the following blank line will be included before header. This is not a comment.

<?php
php code2 here
?>

The reason is that after “php code1 here” php parser is switched off with ?> and all after this close tag is printed out until next php on switching tag <?php before “php code2 here“. The same is true for blank lines and spaces at the beginning and the end of a file. All the major files must start with <?php and must end with ?>. No blank lines around them are allowed.

Solution:
Modify the php code in such a way that php code does not output anything. If you want to have blank lines or whatever, you can. Just hold php parser switched on all the time. In the example above this can be achieved this way:

<?php
php code1 here


// The blank line above this, this line and the following blank line will not be included before header.
This is a comment.

php code2 here
?>

Also remove any leading and trailing blank lines and spaces or anything else.

Hope this will help.

Recommended: WordPress Dream Theme

Technorati tags:

One Response to "Warning: Cannot modify header information - headers already sent by"

Follow-up responses to this entry through the RSS feed, Leave a Reply or Trackback from your own site.
LeraJenkins said,
in June 25th, 2009 at 9:25 pm

Bravo, your idea it is brilliant

Leave a Reply

 Username (*required)

 Email Address (*private)

 Website (*optional)