stuck with php redirects !!!

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
jon22
Forum Newbie
Posts: 3
Joined: Wed Jun 16, 2010 2:32 pm

stuck with php redirects !!!

Post by jon22 »

Hi everyone,

Im trying to redirect all my affiliate links through 1 file, go.php although I can't seem to get it working

my urls are:

mydomain.com/go.php$id=01
mydomain.com/go.php$id=02 etc

my code is as follows:

Code: Select all

<?php
switch ($id) {
case "01":
header("Location: $http://tidd.ly/d4db0265");
exit;
case "02":
header("Location: $http://tinyurl.com/2dnjpp9");
exit;
}
?>
I can get one url working on it's own but need to do multiple urls via 1 page, also is this safe?

Thanks
John
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: stuck with php redirects !!!

Post by AbraCadaver »

1. You have $id in the URL, it should be ?id
2. switch ($id) should be switch ($_GET['id'])
3. What's with $http that's not a variable unless you've defined it somewhere
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: stuck with php redirects !!!

Post by Benjamin »

I would do it a little differently.

Code: Select all

$domains = array(
    '01'    => "http://tidd.ly/d4db0265",
    '02'    => "http://tinyurl.com/2dnjpp9",
);

if (isset($_GET['id']) && isset($domains[$_GET['id']])) {
    header("HTTP/1.0 301 Moved Permanently"); 
    header("Location: {$domains[$_GET['id']]}");
    exit();
} else {
    echo "Invalid Destination";
}
jon22
Forum Newbie
Posts: 3
Joined: Wed Jun 16, 2010 2:32 pm

Re: stuck with php redirects !!!

Post by jon22 »

AbraCadaver wrote:1. You have $id in the URL, it should be ?id
Sorry that is a mistake in the post the urls are actually ?id.

Both of your ways work great. Thank you very much!

John
Post Reply