Forum Moderators: phranque
What I am trying to accomplish is to have a single text link on a page that will direct to a random list of URLs when clicked. I'm not even sure if that makes sense. I want to build a list of URLs, and through a single link on my page, the direction will go to any of the links in the list randomly.
Is this possible, and does anyone have any information on how I can accomplish this?
Thanks!
The one that will always work is a server-side method;
href="random-url-script.php"
I used PHP because that's what everyone seems to like these days, it can be PHP, ASP, Perl, Cold Fusion . . . whatever.
The second is the same thing with Javascript. The down side of this is it won't work for Javascript-disabled browsers and the URL's are likely not to index in SERPS.
In both cases, you'd have a list of URL's (array) and use random generation methods to get the random url. That is, if you have 20 URL's, you'd pick a random number between 0 and 19 (arrays are zero-based, the first index is 0.)
It gets a little more complex for redundant calls; to avoid picking the same number twice you need to create a second array of "visited" URL's. If the pick is in the "remembered" array, keep picking until you get one. If the remembered array has all the elements of the original, reset it.