PHP: header alternative?
Ralph’s Question:
I wanted to know if the echoing the following would be a good alternative to using header(“Location: index.html”) without having to use output_buffering
echo "<script type='text/javascript>window.location = 'index.html';</script>";
There are times I would like to redirect possibly in a body, would the above work fine or is it worth turning on the output_buffering option and just user header()?
header()
defines the page the user is viewing. Using output buffering forces to ignore the previous output buffer, so it is not considered an efficient way to redirect. So, here are my suggestions:
-
If your only target is to redirect, then make sure you output nothing before
header
statement executes. In this caseheader
is appropriate. -
If you need to show your page and based on user interactivity need to redirect to the different page, use the JavaScript Redirection.