Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

How can this be done....

Options
  • 21-12-2007 7:34pm
    #1
    Banned (with Prison Access) Posts: 339 ✭✭


    i want to have a user of a site click a link and have that user taken randomly to one of 3 pages... ?

    MM05


Comments

  • Registered Users Posts: 6,440 ✭✭✭jhegarty


    i want to have a user of a site click a link and have that user taken randomly to one of 3 pages... ?

    MM05

    Javascript is the easiest way ....

    http://www.bloke.info/javascript/RandomURL/


  • Banned (with Prison Access) Posts: 339 ✭✭mastermind2005


    yea little pixie ;)


  • Banned (with Prison Access) Posts: 339 ✭✭mastermind2005


    i take that back... i was hoping to be able to just past the code into my page and for it to work.... :o


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    Still having problems, i'd imagine this be a simple enough javascript.

    Though it is just as easily done with PHP if not easier


  • Registered Users Posts: 35,524 ✭✭✭✭Gordon


    This is one way of doing it. I'm a bit clunky at PHP but it seems to work. You define an array of three pages, then make a random number between 0 and 2 and then output link with the random number as the key of the array.
    [PHP]<?php
    $array = array('page1.htm' , 'page2.htm' , 'page3.htm');
    $random_number = rand(0, 2);
    echo "Random <a href='". $array[$random_number] . "'>link!</a>";
    ?>[/PHP]

    Or are you wanting the link to stay the same and the link then takes you to a random page after clicking - so you click on "random/index.htm" and it takes you to "random/randompage2.htm"?


  • Advertisement
  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    or make it a bit shorter by:
    [php]
    $array = array('page1.htm' , 'page2.htm' , 'page3.htm');
    echo "Random <a href='". array_rand($array,1) . "'>link!</a>";
    [/php]

    :)


  • Registered Users Posts: 35,524 ✭✭✭✭Gordon


    Ah, very good! My php code must be twice the length of proper coders'! Not that I write much code that is.


Advertisement