FutureQuest, Inc. FutureQuest, Inc. FutureQuest, Inc.
Knowledgebase: PHP/MySQL
Header errors?
Posted on 28 January 2004 08:12 PM

I have been pretty frustrated with a lot of header errors I am getting. I know you do not support third party PHP apps, but every app I use gets some kind of error related to information being added to the header after it is sent.

Example 1: Warning: Oops, php_SetCookie called after header has been sent in filename.php on line 1

Example 2: Warning: Cannot add more header information - the header was already sent (header information may be added only before any output is generated from the script - check for text or whitespace outside PHP tags, or calls to functions that output text) in /big/dom/xdomain/www/directory1/directory2/filename.php on line 1

I know it is not your job, but I am certain that the error is being caused partially by how the script is written and how the server is configured. Any help is appreciated?


What this means is that PHP has already sent the page header. The header can contain:

- Content type
- File size and modified date
- Any cookies or other user data

Each header is on a separate line and once you send a blank line this tells the server and browser that the rest of the data will be the file content (HTML, binary image data, etc).

Since PHP handles the standard headers automatically, once you send any data to the browser, PHP sends that blank line to indicate the start of content. Once that is done, you cannot send another header - PHP cannot back up, as it has already sent the data to the browser.

The most common reason for this is when there is HTML or a space before your first PHP open tag. If there is, PHP sends that as page content - after sending the proper headers.

End result - it's a coding error, but a common one especially for those new to PHP.