Possible Duplicate:
Headers already sent by PHP
I have a php webpage that displays a drop down menu
The drop down menu provides links to a back-end script that will run a query and set some session variables. Then it redirects to the results page with
header('Location: search_results.php');
the redirect dies with "Cannot modify header information - headers already sent"
trying to figure out a way around this. The "Modify header" error is an error that's always local from the PHP script that's currently running? Or is it the whole session in general?
thanks, JM
Without looking at your code, I'll hazard a guess that you have HTML before the header
PHP code. Headers need to be parsed before HTML.
Make sure you're not outputting anything before that line (such as whitespace, or other output).
An easy way to do this is to turn on the output buffer:
ob_start();
And clear it when appropriate:
ob_end_clear(); // erases output buffer
// or
ob_end_flush(); // sends output buffer to screen
However, the proper solution is to go through your code and ensure there are no stray output statements.
You can try using output buffering by issuing an ob_start()
at the beginning of the PHP script.
A common cause of this error is having a whitespace (or sometimes a BOM) before the starting <?php
tag; the Header check is local, it is not session-wide. On the other hand, it is influenced by other included PHP files, so you'll have to check them too.
You can use a meta redirect
<meta http-equiv="refresh" content="2;url=http://google.com/">
The above will refresh the page in 2 seconds to http://google.com/ Then javascript redirect
<script type='text/javascript'>
document.location.href='http://google.com';
</script>