Cannot Add Header Information - Headers Already SentLast Update: 6th April, 2005
Article ID: 15


Introduction

The following warning message is shown when PHP experiences a problem:

Warning: Cannot add header information - headers already sent by (output started at /directory/to/starting_file.php:XXX) in /directory/to/calling_file.php on line XX


The problem occurs when content has been sent to the client and PHP has been instructed to set header parameters via the header() function, or when starting the session via the session_start() function.

Solution

The problem can be solved by walking through the code logic flow in the files involved, which are mentioned in the warning message, to make sure no headers are being set after content has been sent to the client.

A common cause to the problem is spaces ("whitespace") existing before the first <?php tag and/or after the last ?> tag with the files involved. By removing all spaces so that <?php is at the very start of the file and that ?> is at the very end of the file, no content would have been sent to the client and headers can be set safely.

Open the file in a text editor -> place your mouse cursor after the very last ?> tag at the very end of the file and press the 'delete' key on your computer keyboard. Make sure that whitespace does not exist before the opening <?php tag at the very beginning of the file - delete whitespace if present. Save and upload the file to your installation.

PHP can only set HTTP headers when no content has been sent to the client.

 

 

Trademark Policy | Copyright Policy | Sitemap

Copyright © 2000-2005 osCommerce. All rights reserved.