Welcome to the OzoneAsylum FaqWiki
Frequently Asked Questions
Server Side Coding

How can I redirect a page with PHP? Pages that link to <a href="https://ozoneasylum.com/backlink?for=5038" title="Pages that link to How can I redirect a page with PHP?" rel="nofollow" >How can I redirect a page with PHP?\

With credits to mr.maX.

Adjust the code below to suit your needs.

header("Refresh: 3; URL=/index.phpnn");
echo " "; // NN4 requires that we output something...

If you didn't want a timed redirect then you could use this:

header("Location: ADDRESS");

Make sure that you do not output to the browser before you perform the redirection. Your attempt at redirection will fail if you output anything with a message similar to

Cannot modify header information - headers already sent by (output started .....)

This means that the redirection must be found before any HTML code.
This includes newlines in any includes you may have, or newlines before the first <?php.

Relevant FAQs:

How can I redirect a page with HTML?

How can I redirect a page with JavaScript?

How do I redirect a page using Apache?

How to redirect using ASP

Relevant note:

As of writing this FAQ is number 2 at Google in the search for the terms php, redirect (up from 9) and 9 for the terms php, redirect, page (previously 14).


(Edited by Tyberius Prime on 06-09-2004 16:31)

« BackwardsOnwards »

Show Forum Drop Down Menu