Need Random Link REdirect PHP code : i.e. randomly send users to listed few urls

Discussion in 'PHP' started by seopriest, Nov 21, 2012.

  1. #1
    Hi

    I Need Random Link REdirect PHP code : i.e. randomly send users to listed few urls

    ive searched these 2 codes but none of them worked


    $sites = array(
    'http://www.google.com/',
    'http://www.msn.com/',
    'http://www.yahoo.com/'
    )
    header('Location: '.$sites[array_rand($sites)]);
    die();
    Code (markup):


     <?php
    $num = Rand (1,3);
    switch ($num) {
    case 1: header('Location: http://www.site1.com//');
    break;
    case 2: header('Location: http://www.site2.com/');
    break;
    case 3: header('Location: http://www.site3.com//');
    break;
    }
    ?> 
    Code (markup):

    PLEASE he
     
    seopriest, Nov 21, 2012 IP
  2. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    first step random the array and then header location to array [0]
     
    ogah, Nov 21, 2012 IP
  3. seopriest

    seopriest Member

    Messages:
    347
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #3
    im not techy .. so please post exactly :)
     
    seopriest, Nov 22, 2012 IP
  4. ogah

    ogah Member

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    randomize array more simple use shuffle.
    so your first code will become like this
    $sites = array(
    'http://www.google.com/',
    'http://www.msn.com/',
    'http://www.yahoo.com/'
    );
    shuffle($sites);
    header('Location: '.$sites[0]);
    die();
    Code (markup):
    CMIIW
     
    ogah, Nov 22, 2012 IP