Redirect few percentage of visitors ?

Discussion in 'Programming' started by vic_msn, Dec 9, 2008.

  1. #1
    Hello
    I would like to know how can I redirect every 4th visitor to another website of mine.
    Suppose I get 100 visits to my website(Eg: mywebsite.com)
    
    <?php
    if(some condition){
    header(Location: "http://mywebsite.com/link1.php");
    else{
    header(Location: "http://mywebsite.com/link2.php");
    }
    ?>
    
    PHP:
    I would like to redirect 10% to one link and rest to another link.
    Can this be done ?

    Please help
     
    vic_msn, Dec 9, 2008 IP
  2. firman01

    firman01 Well-Known Member

    Messages:
    155
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    165
    #2
    ok let say we have 100% here

    we generate random number from 1 to 100. mt_rand(1,100);

    so you will put the condition

    if(mt_rand(1,100) <= 10) {
    //goto url that in 10 range
    }
    else {
    //goto url in 90 range
    }
     
    firman01, Dec 9, 2008 IP