Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

How can this be done....

  • 21-12-2007 07: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, Registered Users 2 Posts: 6,131 ✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 35,522 ✭✭✭✭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, Registered Users 2 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, Registered Users 2 Posts: 35,522 ✭✭✭✭Gordon


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


Advertisement