A redirect that works on percentages?

Discussion in 'Programming' started by checksum, Aug 26, 2007.

  1. #1
    Is there any way I can set up a redirect that redirects to one page 95% of the time and another 5% of the time?
     
    checksum, Aug 26, 2007 IP
  2. ednit

    ednit Peon

    Messages:
    152
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sure, this can be done with probably any server side language with use of a database. I wouldn't know of anything available for free that would do that, but a programmer could put something together fairly easily.
     
    ednit, Aug 26, 2007 IP
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #3
    Maybe something like this is enough:
    
    <?php
    
    if (mt_rand(1, 95) >= 95)
    {
    	header('Location: http://5percent.com/');
    }
    else
    {
    	header('Location: http://95percent.com');
    }
    
    exit();
    
    ?>
    
    PHP:
     
    nico_swd, Aug 26, 2007 IP
    checksum likes this.
  4. checksum

    checksum Notable Member

    Messages:
    2,633
    Likes Received:
    101
    Best Answers:
    0
    Trophy Points:
    230
    #4
    I'm not much of a coder, would I place this in a php file or in the body of the html?

     
    checksum, Aug 26, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    In a PHP file. But no other content could go there. It would redirect immediately to one of these pages.
     
    nico_swd, Aug 26, 2007 IP
  6. checksum

    checksum Notable Member

    Messages:
    2,633
    Likes Received:
    101
    Best Answers:
    0
    Trophy Points:
    230
    #6
    Ah I see, thanks a lot man.
     
    checksum, Aug 26, 2007 IP
  7. checksum

    checksum Notable Member

    Messages:
    2,633
    Likes Received:
    101
    Best Answers:
    0
    Trophy Points:
    230
    #7
    Would this be the correct code for a 75/25 percentage?

    <?php

    if (mt_rand(1, 75) >= 75)
    {
    header('Location: http://www.75percentage.com');
    }
    else
    {
    header('Location: http://www.25percentage.com');
    }

    exit();

    ?>
     
    checksum, Aug 26, 2007 IP
  8. kemus

    kemus Guest

    Messages:
    487
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Actually, I think there's an error with both those codes.
    <?php
    
    if (mt_rand(1, 75) >= 75)
    {
    header('Location: http://www.75percentage.com');
    }
    else
    {
    header('Location: http://www.25percentage.com');
    }
    
    exit();
    
    ?>
    Code (markup):
    Will do it on a 1/75 chance.

    <?php
    
    if (mt_rand(1, 100) >= 75)
    {
    header('Location: http://www.75percentage.com');
    }
    else
    {
    header('Location: http://www.25percentage.com');
    }
    
    exit();
    
    ?>
    Code (markup):
    Would do it on a 25% chance, but it's still flipped...

    <?php
    
    if (mt_rand(1, 100) >= 75)
    {
    header('Location: http://www.25percentage.com');
    }
    else
    {
    header('Location: http://www.75percentage.com');
    }
    
    exit();
    
    ?>
    Code (markup):
    Is the correct way to go about it.
     
    kemus, Aug 28, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    ^^ Yep, my bad. You're right. :)
     
    nico_swd, Aug 29, 2007 IP