I have a function which needs to redirect the page if a variable is set etc…
The problem is, this function is at the bottom of the php page.
This means, I have outputted alot of information, so I get a headers warning.
“Warning – Headers already sent by …”
Is there any way to redirect after headers are sent?
What you should do is put
ob_start() at the very beginning of your page, and
ob_flush() at the very end. This way you don’t run into headers already sent errors.
See those functions for further reference.
There are ways, but they’re basically workarounds:
The simplest one is the
<meta http-equiv="Refresh" content="0;http://www.example.com/newlocation">
- some browsers will not like this when it’s outside of the
<head>element, and drop into quirks mode
<script> window.location = 'http://www.example.com/newlocation'; </script>