Reputation:
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?
Thanks
Upvotes: 7
Views: 11594
Reputation: 92762
There are ways, but they're basically workarounds:
The simplest one is the meta http-equiv
:
<meta http-equiv="Refresh" content="0;http://www.example.com/newlocation">
<head>
element, and drop into quirks modeOr, you can try the JavaScript redirect:
<script>
window.location = 'http://www.example.com/newlocation';
</script>
Upvotes: 13
Reputation: 4398
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.
Upvotes: 24