[RESOLVED] How can I get header() to work? I can't put it before the output
Hi,
My index.php is constructed in such a way that I can't figure out how to use header() before any of the included php files.
The thing is: I always stay on index.php, in the MAIN div because I use $_GET variable to define actions (such as action=login, =displaycategories, =viewpost) and I use include files, depending on which action is triggered.
So when I use the login feature, I can't use header() to redirect the browser to index.php, because output has already been generated in the header.
How can I solve this problem?
Below is my code for index.php.
Thanks a lot
Code:
<body>
<div id="wrap">
<div id="header">
<center>this is the header</center>
</div>
<div id="main">
// THIS is where all the PHP stuff happens.
</div>
<div id="sidebar">
<?php include ('include/leftmenu.php');?>
</div>
<div id="footer">
<center>this is the footer</center>
</div>
</body>
What this will do is that it will gather everything that is output into a 'buffer' and ob_end_flush() will be the line that actually 'echoes' the output, so header() always comes before that.
Note that you can do a lot more with output buffer, read more here.
Bookmarks