|−|'''Q. What causes "Warning: Cannot modify header information - headers already sent " to appear?''' |+|
| || |
|−|An example: |+|
the phpfile of the , the of
|−|I have Mambo pretty much installed, but when I get to the index.php file of the site, |+|
|−|it has the mambo default site with the following lines above it: |+|
|−|(example of error code displayed) |+|
| || |
source lang="php"> GLOBALS[$key2]=$value2; } } } ?> </ source> |+|
|−|'''Warning:''' Cannot modify header information - headers already sent by (output started at |+|
<>?></> at PHP filesthe PHP of. any blank the and will .
|−|in /home/somesite/somefolder/anotherfolder/folder/includes/mambo.php on line 274 |+|
|−|A. PHP files cannot have any blank spaces/lines outside the PHP code and will result in this type of error. |+|
|−|There cannot be any white space or blank lines either before or after the opening and closing PHP tags (). |+|
|−|A single extra character, even a blank space, can cause this. |+|
|−|Look at any files that you have modified to see if there is any such space. |+|
|−|Online file managers, such as used in cPanel, when used to edit files will often add a blank line at the end of the code. |+|
|−|Always check for extra spaces/ lines after the PHP code before saving .php files. |+|
Revision as of 02:29, 24 July 2008
In the HTTP protocol a server response consists of a group of headers followed by a body, separated by a single blank line (i.e. a line containing only a carriage-return). This warning message is produced by PHP if a program attempts to send an additional HTTP header after the separator (and hence all the headers) has already been sent.
By far the most common cause of this problem is that one or more PHP files contains characters (usually a space or an empty line) outside of the <?php and ?> tags. To fix the problem you should examine the PHP file indicated in the warning message and remove any blank characters at the beginning and end of the file. Some text editors, including some online file managers, are prone to automatically adding extraneous line-ending characters at the ends of files, particularly when not configured to do otherwise.
- Remove the closing ?> tag at the end of your PHP files. It actually serves no useful purpose as the PHP interpreter knows that end-of-file means end-of-PHP too. Removing it means that any extra blank characters added by your editor will have no effect on the output generated and so will not prevent additional HTTP headers from being sent.