View Single Post
Old Jan 12th, 2008, 8:37 AM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Posts: 1,799
Rep Power: 5 Sane will become famous soon enough
Re: Warning: Cannot modify header information - headers already sent by (output started at

The function, "header", can not be called if you've already made the script output text to the client.

For example:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. echo 'Hello World!'
  4. header('Content-type: text/plain');
  5.  
  6. ?>

Will throw an error, because it tried to modify the header after all of the headers were sent to the client.

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. header('Content-type: text/plain');
  4. echo 'Hello World!'
  5.  
  6. ?>

This will work. Because the header is modified, and then output is sent.
Sane is offline   Reply With Quote