Re: buffering to allow headers in code? [message #170173 is a reply to message #170169] |
Thu, 14 October 2010 20:51 |
Hamish Campbell
Messages: 15 Registered: September 2010
Karma:
|
Junior Member |
|
|
On Oct 15, 5:32 am, MikeB <mpbr...@gmail.com> wrote:
> Since I'm trying to display the name of the logged in user on the left
> pane, that code is included before I run the code in the "main" cell,
> hence my timing problem
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,
Hamish
|
|
|