buffering to allow headers in code? - Page 2

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

Re: buffering to allow headers in code?

Quoted text here. Click to load it

This is what was meant by "restructuring your code". You should really
perform any state operations (like 'login user x', 'delete page y',
etc) before you start building any output. Obviously, since you're
just starting out, it's not helpful to talk about MVC patterns (worth
a Google and some questions to your instructor, just to get your
money's worth :P), but try to think of the actual output as the final
step in the process. I.e., PHP gets the request, does all the
checking, redirection, database stuff, etc - before a single line of
output is sent to the buffer/browser.

in the meantime, sending a header redirect will work - just don't
forget to die() or exit() after the header call to stop further
(unnecessary) processing. It is a classic security blunder to assume
that code execution stops after the header is sent purely because the
browser goes on it's merry way.

Hope this helps,


Re: buffering to allow headers in code?

On 14/10/10 17:32, MikeB wrote:

Quoted text here. Click to load it

The page is generated. At the point that the page is generated, you are
either logged in, or not logged in.

If you are not logged in, then presumably an option to log in is
displayed, and then presumably the whole page is reprocessed from the start.

But, this time round, you can:

(a) invoke a session handler
(b) process the log in details before you do anything else
(c) store the log in state and username in a session variable

before processing the nav menu.

Now, if you did that first, when you get down to doing nav, you can test
the logged_in session variable, and if the user is logged_in, use the
username session variable in generating your navigation bar.


Denis McMahon

Site Timeline