rodrico101 Posted July 27, 2008 Share Posted July 27, 2008 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 https://forums.phpfreaks.com/topic/116869-php-redirect-one-page-multiple-redirects/ Share on other sites More sharing options...
DarkWater Posted July 27, 2008 Share Posted July 27, 2008 <?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 https://forums.phpfreaks.com/topic/116869-php-redirect-one-page-multiple-redirects/#findComment-600951 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.