[INFORMATIVE] Header() Redirect
Hi all,
Today I've been busy with a redirection page.
I got into a conflict when I tried to redirect it halfway my page.
As it was hard to recode everything to the top, I looked up a solution and I'd like to share it with you, as I've seen many threads here where this isn't mentioned.
I'm talking about the ob_start and ob_end_flush functions.
It works great for me.
Now I'm pretty sure you know those functions exist.
Why don't you use/advise them?
Re: [INFORMATIVE] Header() Redirect
Because it's better practice to work out whether or not you need to redirect or not before beginning any output.
All processing logic should be completed before output logic begins.
Output buffers have their uses but avoiding the problems associated with spaghetti logic or non-decoupled processing/output is not what they are for.
Re: [INFORMATIVE] Header() Redirect
The issue could be better solved by breaking up your application logic and your view logic -- meaning all code should be processed before you output anything.
This can be accomplished using the MVC (model-view-controller) architecture or using templating.
Using the output buffering, like penagate said, is a hack to make bad code work.