Welcome to the OzoneAsylum FaqWiki
Frequently Asked Questions
Server Side Coding
PHP

How can I redirect a page with PHP? Differences 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? Differences" rel="nofollow" >How can I redirect a page with PHP? Differences\

With credits to mr.maX.

Adjust the code below to suit your needs.

code:
<?php
header("Refresh: 3; URL=/index.phpnn");
echo " "; // NN4 requires that we output something...
exit();
?>



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

code:
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

quote:
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 HTML?

+ How can I redirect a page with JavaScript?

-How can I redirect a page with JavaScript?

+ How can I redirect a page using Apache?

-How do I redirect a page using Apache?

+ How can I redirect a page 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)
-
- (Edited by: Tyberius Prime on Sun 27-Apr-2003)
-
- (Edited by: Tyberius Prime on Sun 27-Apr-2003)
-(Edited by WarMage on 06-08-2004 10:18)
-(Edited by Tyberius Prime on 06-08-2004 22:36)

« BackwardsOnwards »

Show Forum Drop Down Menu