Forum Moderators: coopster
Yes, I read all over the place that I must not output anything else to the server before the header.
OK, but how does that work in real life, when I have to use html to draw tables, declare CSS styles, etc?
I just cannot find a real-life example of a php file that manages that...
1) upload to server a .htaccess file containing "PHP_FLAG output_buffering on".
(tried, but my server returns an error)
2) place <? ob_start();?> at the very beginning of your php page and <? ob_end_flush();?> at the very end. (works so far)
If you want to redirect them after stuff has loaded then use Javascript.
<script language=javascript>
parent.leftFrame.location="menu.php";
parent.mainFrame.location="login.php";
</script>
This is an adaptation of a line I have used .. in this case, I have a frame structure (leftFrame and mainFrame) for a menu and a main page. So do a conditional check (after submit for instance .. or whatever) and then execute this code. Be sure to note that the "parent.leftFrame.location" part of that will have to change according to the structure of your page.
Another way of doing it is to stay with HTML:
<meta http-equiv="refresh" content="0; url=login.php">
Use this in the same way, but executing after a conditional statement is met. This will only affect the page in which it is embedded. That is great for some (maybe even most) redirects. But if you need to affect more than one page at a time, use the JavaScript example. One nice thing about the meta redirect is that you can assign a time value to it (redirect after x number of seconds). That is what the number is for in: content="#
I tend to shy away from messing with the header at all, but that is due to my lack of comfort with it (not because it is insufficient for the task).
Hope that helps,
Josh