PHP Page Redirection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
noah_xumin
Forum Newbie
Posts: 3
Joined: Wed Dec 23, 2009 10:08 am

PHP Page Redirection

Post by noah_xumin »

Hi there,

I have some two pages like http://www.domain.com/index.php?p=123 http://www.domain.com/index.php?p=456 . Is there anyway that I can set the page redirection so that when people visit http://www.domain.com/index.php?p=123 page, this page will be redirected to http://www.google.com and when people visit http://www.domain.com/index.php?p=456 page, this page will be redirected to http://www.yahoo.com ?

Thank you very much,

Noah
User avatar
jazz090
Forum Contributor
Posts: 176
Joined: Sun Apr 12, 2009 3:29 pm
Location: England

Re: PHP Page Redirection

Post by jazz090 »

Code: Select all

<?php
$p = $_GET['p'];
if ($p == 123){
    header('Location: http://www.google.com');
}
else if ($p == 456){
   header('Location: http://www.yahoo.com');
}
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Page Redirection

Post by requinix »

Don't forget to put an exit; or die; after the header() - otherwise the redirection happens after PHP has processed the entire script.
noah_xumin
Forum Newbie
Posts: 3
Joined: Wed Dec 23, 2009 10:08 am

Re: PHP Page Redirection

Post by noah_xumin »

Thank you guys! Really appreciated it! It works like charm!
Post Reply