Jump to content

Php Redirect-One page, multiple redirects


rodrico101

Recommended Posts

Hello,

 

This is my first post and I have a little background in PHP.

I am trying to write a php page to redirect several affiliate links.

 

What I would like to do is have www.mysite.com/links.php ..this one page would be where the links/clicks would go before the redirects occur.

 

I am trying to figure how to do a IF statement so that I can say if, www.mysite.com/links/affiliate1, then go to affiliate1.com, if www.mysite.com/links/affiliate2 then go to affiliate2.com and so on.  I will probably have about 20-30 different redirects and do not want a separate php page for each link.

 

I know the basic code: (ie <?php header('Location: http://www.affilate1.com'); ?>  But confused on how to write the if statement.

 

I don't particularly want to do it via a .hta rewrite so looking to do via php.

Thanks for any help.

 

Rod

<?php
$affiliates = array('affiliate1' => 'http://www.example.com',
                          'affiliate2' => 'http://www.something.com',
                          'affiliate3' => 'http://www.bored.com');
foreach ($affiliates as $affiliate => $link) {
    if ($affiliate == $_GET['link']) {
            header("Location: $link");
    }
}
?>

 

That's how I'd do it if I wasn't going to use a database or anything.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.