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

Need help Php redirect to random url

Discussion in 'General Scripting Chat' started by Scariot, Feb 13, 2016.

  1. Scariot

    Scariot Regular Member

    Joined:
    Oct 5, 2013
    Messages:
    271
    Likes Received:
    214
    Occupation:
    Internet Marketeer
    Location:
    www.googleheart.com
    Hi guys I'm not quite a coder (newbie) I need some help on url redirect using phpExample site.com/redirect.php then redirect to a random url in list Please help thank you.
     
  2. lukapresic

    lukapresic Junior Member

    Joined:
    Jan 18, 2014
    Messages:
    196
    Likes Received:
    30
    Occupation:
    System admin
    Location:
    Mars
    Home Page:
    • Thanks Thanks x 1
  3. ryanh4xor

    ryanh4xor Newbie

    Joined:
    May 10, 2013
    Messages:
    27
    Likes Received:
    10
    <?php


    $links = array('Your url 1',
    'Your url 2',
    'Your url 3');


    $randNum = rand(0, count($links));
    header("Location: " . $links[$randNum]);


    ?>
     
  4. Scariot

    Scariot Regular Member

    Joined:
    Oct 5, 2013
    Messages:
    271
    Likes Received:
    214
    Occupation:
    Internet Marketeer
    Location:
    www.googleheart.com
    it's not working with 4 or more only works at 3 can you give me a sample for list or url? maybe in text file?
     
  5. Scariot

    Scariot Regular Member

    Joined:
    Oct 5, 2013
    Messages:
    271
    Likes Received:
    214
    Occupation:
    Internet Marketeer
    Location:
    www.googleheart.com
    Thanks I found one
     
  6. clarkxie

    clarkxie Junior Member

    Joined:
    Jun 20, 2015
    Messages:
    130
    Likes Received:
    11
    you want to use for what purpose? and how many urls?
     
  7. ryanh4xor

    ryanh4xor Newbie

    Joined:
    May 10, 2013
    Messages:
    27
    Likes Received:
    10
    ohhh sorry I just typed in rush and did not check my code, following is fixed one and should work perfectly...i have checked it this time

    <?php


    $links = array('your link',
    'your link',
    'your linkl',
    'your link');


    $randNum = rand(0, 4);
    header("Location: " . $links[$randNum]);


    ?>