Redirecting page without using HEADER(), is there another way?

i want to know or is there any other way to redirect a page without using a header().

I’m sick using header() it is not very flexible, i’m using header() in the middle of my codes and it always trew me a message error –>

Warning: Cannot modify header information - headers already sent by (output started at…

yes, i know about the cause of this error it has white spaces and this should be put at the first and no white spaces before the header()…

any help from you guys is very appreciated thanks in advance.

You can use this anywhere in your code, even after output has begun:

echo '<META HTTP-EQUIV="refresh" content="0;URL=' . $URL . '">';

Best regards,


<meta http-equiv="refresh" content="2;url=">

where 2 is the number of seconds

Thanks guys it helps me a lot.

real http headers are often a much better choice. you should try to use them when you can.

if you are having a difficult time restructuring your code in a way that handles the logic of the script before the output, you could always use output buffering.

just call ob_start() on the first line of your php script and then you can send headers anywhere in the script.

Why are they a better choice?


Because they don’t rely on client-side redirects, which can be unsupported or disabled.

Something is wrong with your code structure/logic if you want to display something to the user and then immediately redirect them before they can even see the output. If you intend to redirect someone then don’t output anything.

Is that a serious comment? If the request doesn’t come from the client where do you think it comes from?

Header redirects are better because the document doesn’t need to be opened and rendered to find out there is a redirect.