faqts : Computers : Programming : Languages : PHP : Installation and Setup

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 1 people (100%) answered Yes
Recently 1 of 1 people (100%) answered Yes

Entry

could you please tell me what this means. Warning: Cannot modify header information - headers alread

Jun 24th, 2004 21:19
Michael Phipps, Richard Brown, http://www.php.net/manual/en/function.header.php


Let's say you are writing a PHP script that will redirect to another 
page
This code will cause the error
1:
2: <?php
3: header("Location: http://www.example.com/"); /* Redirect browser */
4: 
5: exit;
6: ?> 
This code will work
1: <?php
2: header("Location: http://www.example.com/"); /* Redirect browser */
3: 
4: exit;
5: ?> 
If you have any output, including a blank line before your php code, 
you get an error "Warning: Cannot modify header information - headers 
already sent" because the moment you send any output to a browser, the 
header information will be sent.  After that header is sent, and 
changes to the header can not happen, because the header has already 
been written, so an error is produced
You can use output buffering to get around this problem.
Some useful URL's to help you further are:
Header:  http://www.php.net/manual/en/function.header.php
Output Buffering: http://www.php.net/manual/en/function.ob-start.php