FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » General » PHP discussions » Undefined Index Troubles... [Help Please]
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Undefined Index Troubles... [Help Please] [message #31405 is a reply to message #27004] Fri, 21 April 2006 08:59 Go to previous messageGo to previous message
richardlynch is currently offline  richardlynch   United States
Messages: 8
Registered: April 2006
Karma:
Junior Member
A minimal HTTP document from Server to Browser might look like:

---------------------- this line is not part of it ------------
200 Success
Content-type: text/html
Content-length: 4325
X-Powered-by: PHP

<html><body>Hello World</body></html>
---------------------- this line is not part of it ------------

Now, remember, this is going out piece by piece, line by line, letter by letter.

At any point in time, in slow-motion instant replay, maybe only SOME of the lines have gone from the server to the browser.

Look closely at the data above.

You see that blank line after the X-Powered-by: PHP and before the HTML tags?

*THAT* line is super crucial.

THAT line is a blank line, and the very first blank line indicates to the browser that the "headers" (those lines above the blank) are "done" and the HTML is about to start.

Now, you don't normally see the headers, though Firefox has a nifty plug-in to show them which you should get. You are using Firefox,right?

Anyway, here's the thing.

As soon as PHP has to send out some content -- some part of the HTML (like <html> usually) or even a blank line *before* your HTML, then it *has* to send all the headers out, and the blank line to indicate the END of the headers.

So what the error message is telling you is that on line 16 of your script, you printed/echo'ed something out, or you have a blank line, or you have an error message of some kind printing something out.

And when that happened, PHP sent all the headers, and then a blank line, and then started sending out your HTML (or blank lines or whatever you have on line 16).

Now, come line 124, you're trying to send a header out using the header function.

Only problem is, it's WAY too late.

The headers all got sent out at line 16, and PHP has already started sending content.

If line 16 is just a bad line or something, fix it and this problem goes away.

Otherwise, you can do one of two things:

1. The lazy, disorganized, quick, dirty solution is to turn on "output buffering" with http://php.net/ob_start (or in php.ini)

2. Re-arrange your code logically so that the HEADERS (which come oat the "head" of an HTTP stream, are all worked out at the tip-top of the document, and the actual HTML all comes later. This will make your code more organized and more logical, but requires actual thinking and work.

I always recommend #2, personally. Smile
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: strange behaviour - fwrite
Next Topic: invalid argument
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 21:07:51 GMT 2024

Total time taken to generate the page: 0.04690 seconds