How do I make a redirect in PHP?

Summary of existing answers plus my own two cents: 1. Basic answer You can use the header() function to send a new HTTP header, but this must be sent to the browser before any HTML or text (so before the <!DOCTYPE …> declaration, for example). 2. Important details die() or exit() Why you should use die() or exit(): The Daily WTF Absolute or relative URL … Read more

How do I make a redirect in PHP?

Use the header() function to send an HTTP Location header: Contrary to what some think, die() has nothing to do with redirection. Use it only if you want to redirect instead of normal execution. File example.php: Result of three executions: Resuming — obligatory die()/exit() is some urban legend that has nothing to do with actual PHP. It has nothing to do with client “respecting” the Location: header. Sending a header does not … Read more