Re: note 38194 added to function.headers-sent

From: Date: Thu, 11 Dec 2003 16:10:05 +0000
Subject: Re: note 38194 added to function.headers-sent
References: 1 2 3  Groups: php.notes 
Request: Send a blank email to php-notes+get-61810@lists.php.net to get a copy of this message
No, only those that apply. Trust me this is huge issue (345 topics on one forum in the last month - 125 topics on another forum in the last two months) These are only forums that I administrate, so God knows how many online forums deal with this nonsense.
header : Remember that *header()* must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with *include()* <http://fr.php.net/manual/en/function.include.php>, or *require()* <http://fr.php.net/manual/en/function.require.php>, functions, or another file access function, and have spaces or empty lines that are output before *header()* is called. The same problem exists when using a single PHP/HTML file. isn't this enough on the page of the function that causes this problem ? the problem is also discussed here : http://php.net/manual/en/faq.using.php#faq.using.headers-sent didou PS : keep on using reply all please
----- Original Message ----- From: "Mehdi Achour" <didou@php.net> To: <kriek@phpfreaks.com> Cc: <php-notes@lists.php.net> Sent: Thursday, December 11, 2003 10:59 AM Subject: Re: note 38194 added to function.headers-sent
Are you going to add this note in every manual page containing "header" ? didou kriek@phpfreaks.com wrote:
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().
---- Manual Page -- http://www.php.net/manual/en/function.headers-sent.php
Edit        --      
http://master.php.net/manage/user-notes.php?action=edit+38194
Delete      --      
http://master.php.net/manage/user-notes.php?action=delete+38194&report=yes
Reject      --      
http://master.php.net/manage/user-notes.php?action=reject+38194&report=yes
Search      -- http://master.php.net/manage/user-notes.php
     


« previous php.notes (#61810) next »