1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Php Redirect of Alternating Aff Links

Discussion in 'PHP & Perl' started by ams007, Jun 6, 2008.

  1. ams007

    ams007 Junior Member

    Joined:
    Apr 18, 2008
    Messages:
    198
    Likes Received:
    41
    Location:
    North America
    <?php
    $links = array();
    $links[] .= "http://www.affiliateprogram1.com/xxxxx";
    $links[] .= "http://www.affiliateprogram2.com/xxxxx";
    $links[] .= "http://www.affiliateprogram2.com/xxxxx";
    $last = count($links) - 1;
    $choice = rand(0, $last);
    header("location". $links[$choice]);
    ?>

    Anything wrong with this code? Is there a better way to do it?

    Thanks!
     
  2. boomboomer

    boomboomer Executive VIP

    Joined:
    Feb 7, 2008
    Messages:
    705
    Likes Received:
    865
    Did you test it?
     
  3. ams007

    ams007 Junior Member

    Joined:
    Apr 18, 2008
    Messages:
    198
    Likes Received:
    41
    Location:
    North America
    Yes, all I get is a blank html page:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META http-equiv=Content-Type content="text/html; charset=utf-8"></HEAD>
    <BODY></BODY></HTML>

    Al
     
  4. boomboomer

    boomboomer Executive VIP

    Joined:
    Feb 7, 2008
    Messages:
    705
    Likes Received:
    865
    your code is alright except the header redirection ...
    change that to
    Code:
    header("location: ".$links[$choice]);
     
    • Thanks Thanks x 1
  5. vivianrollins

    vivianrollins Regular Member

    Joined:
    May 13, 2008
    Messages:
    205
    Likes Received:
    92
    Genjutsu, your sig for blackbook is invalid ... just thought you should know.

    Does anyone have a php or html redirect code to use when using traffic sites such as the one in your sig or buyhitscheap?

    I asked this in a different thread but got no answers.

    Basically, I'm looking for the redirect code to send junk traffic AND for my LP where I actually send real PPC traffic there as well.

    The code should do the following:
    1 direct to offer page
    2 show referral domain as my LP domain for both junk traffic sites and my LP site

    In other words, I need the referral domain to show in the network site as www.mysite.com/aff1.php/html or better yet www.mysite.com

    Anyone?

    Thanks!
     
  6. Essential Clix

    Essential Clix Executive VIP Premium Member

    Joined:
    Jul 30, 2007
    Messages:
    1,755
    Likes Received:
    2,791
    Location:
    USA
    This belongs in the scripting & coding/php section. moving now.
     
  7. ams007

    ams007 Junior Member

    Joined:
    Apr 18, 2008
    Messages:
    198
    Likes Received:
    41
    Location:
    North America
    BoomBoomer - that was it.
    Thanks!
     
  8. ellie

    ellie Regular Member

    Joined:
    May 31, 2008
    Messages:
    237
    Likes Received:
    250
    Location:
    Australia... in a house
    And what to add to stop those who dont have a referer? I have a similar variation on my site and have tried using $null or even "" to catch and redirect all non-referer based traffic though given my background of php, it isnt working.

    Any ideas php guru's? :)
     
  9. efixer1000

    efixer1000 Newbie

    Joined:
    Apr 6, 2008
    Messages:
    1
    Likes Received:
    0
    I tried the following but it only stuffs the second affiliate not the others. Suggestions?

    <?php
    $links = array();
    $links[] = "http://affiliate1.com";
    $links[] = "http://affiliate2.com";
    $links[] = "http://affiliate3.com";
    $links[] = "http://affiliate4.com";
    $last = count($links) - 1;
    $choice = rand(0, $last);
    header("location: ".$links[$choice]);
    ?>
     
  10. nicksor

    nicksor BANNED BANNED

    Joined:
    May 19, 2008
    Messages:
    76
    Likes Received:
    7
    because you're replacing the items in the array. use your favorite search engine "php array" . :)
     
  11. infinite411

    infinite411 Newbie

    Joined:
    Aug 5, 2008
    Messages:
    18
    Likes Received:
    0
    Hey, I was sorta doing the same thing this morning. Only instead of affiliate links, I was randomly pulling user_agent_strings. Here is the code I was using.

    $agentstrings = array(

    "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)",
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)",
    "Opera/9.00 (Windows NT 5.1; U; en)",
    "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008052906 Firefox/3.0"
    );


    $randomagent = $agentstrings[array_rand($agentstrings)];

    echo $randomagent;
     
  12. barigain

    barigain Junior Member

    Joined:
    Aug 23, 2012
    Messages:
    100
    Likes Received:
    12
    Don't be. I've got a nice bit of jQuery that can detect user farts (length and volume) in chrome and safari...