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

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.