note 38193 deleted from function.header by didou
| From: | didou@php.net | Date: | Thu, 11 Dec 2003 15:50:41 +0000 |
| Subject: | note 38193 deleted from function.header by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61806@lists.php.net to get a copy of this message | ||
Note Submitter: kriek@phpfreaks.com
----
This seems to be a common problem amongst new users. For some peculiar reason, they think that they
can output data to the browser, and then send header information. Unfortunately, they are confusing
the HTML meta-refresh tag with the PHP header() function.
"cannot modify header information - headers already sent"
Allow me to elaborate: That error is caused by because you are trying to send header information
AFTER you have sent output to the browser. Usually this is a simple case of reordering an echo
statement or removing white space before and/or after the PHP start and end tags (very common
issue), however you can also use output buffering with the ob_start() and ob_end_flush() functions
which will allow you to place headers and content in any order you want to. Note output buffering
was originally designed to solve HTTP header errors.
<?php
ob_start();
// file content
ob_end_flush();
?>
Although the ob_end_flush() function is not needed in MOST cases because it is called automatically
at the end of script execution by PHP itself when output buffering is turned on either in the
php.ini or by calling ob_start().