Page 1 of 1

stuck with php redirects !!!

Posted: Wed Jun 16, 2010 2:37 pm
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

Re: stuck with php redirects !!!

Posted: Wed Jun 16, 2010 2:44 pm
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

Re: stuck with php redirects !!!

Posted: Wed Jun 16, 2010 2:46 pm
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";
}

Re: stuck with php redirects !!!

Posted: Wed Jun 16, 2010 4:59 pm
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