Re: Cannot modify header information error........usage of header method.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, July 20, 2005 10:15 am, babu said:
> I am using header method to redirect to a certain page.my first question
> is
> 1."Is there any other alternative to this method."
> 2.I am getting the error by using this method. the error is "Cannot modify
> header information - headers already sent by".
> i have seen the php documentation for header method. where there is one
> user comment about this.
> i have followed his steps like removing blank lines, using exit method.
> But the 3rd point that is "HTML goes before any PHP code ", i could not
> follow it , can some one please explain it.

Have you ever heard this expression?

"You can't step in the same river twice"

What it's saying is that after you have stepped in the river, it's not the
same river.  The water is moving and flowing and changing at all times. 
Indeed, the very act of your stepping in the river irrevocably and
eternally alters the river, in some infinitesimal way.

Now, think about the browser and your server in "slow motion"

The browser asks for URL: XYZ.

The server sends out some headers that tell the browser *about* the XYZ
content:

Content-type: text/html
Content-length: ######
Expiration: 1/1/2038


After the headers, your server sends a BLANK LINE.

Then, your server starts sending out the actual CONTENT:

<html>
  <head>
    <title>My Homepage!</title>
.
.
.

Now, sessions and Cookies and similar things go IN THE HEADER.

If you've *ALREADY* sent the BLANK LINE and started sending CONTENT...

IT'S TOO LATE!!!

You can't step back in time and send out headers.  They already *WENT*.

You could just "turn on output_buffering" in php.ini

However, most likely, your program will be a BETTER program if you
re-structure it to keep the headers, and any calulations/operations to
figure out what the headers should be, at the TOP of your code.

Then put in the operations to generate the content.

Keeping your headers and content physically separate in your PHP scripts
will make your code MUCH more readable and maintainable.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux