Random Link - Help

Discussion in 'Programming' started by log0008, Jul 24, 2012.

  1. #1
    Hello,

    I would like to know if the following is possible:

    Create a random link

    As in the following example

    User clicks a link
    1 out of 5 times it sends them to page #1
    2 out of 5 times it goes to page #2
    2 out of 5 times is goes to page #3

    Or something like that??

    Possible or not?

    Thanks
     
    log0008, Jul 24, 2012 IP
  2. freenet

    freenet Peon

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You can do this like this:
    <?php$links = array(array('url' => 'http://google.com', 'name'=>'google'),
                   array('url' => 'http://hotmail.com', 'name' => 'hotmail'),
                   array('url' => 'http://hawkee.com', 'name' => 'Hawkee'));
    $num = array_rand($links);$item = $links[$num];
    
    printf('<a href="%s" title="%s">%s</a>', $item['url'], $item['name'], $item['name']);
    ?>
    PHP:
     
    freenet, Jul 24, 2012 IP