View Full Version : Visitor 1 to URL1, Visitor 2 to URL2 - repeat

09-21-2008, 10:23 AM
I just Twey's reply in 2005 to a person on dynamicdrive looking to create a round robin button:

I am wondering if you know of a way to do the following in ASP or HTML/Javascript?

I am trying to have:

visitor 1 goto url1,
visitor 2 goto url2,
visitor 3 goto url3,

visitor 4 goto url 1,
visitor 5 goto url 2,
visitor 6 goto url 3,

and so on roundrobin, not necessarly by a button. kindoof like how they (http://java-programming.suite101.com/article.cfm/javascript_randomize_landing_page )do it, but without the random element.
Any help would be greatly appriciated!

09-21-2008, 12:17 PM
the first part would be to clearify the visitor-counting issue.

As you can not count visitors with javascript (since it is client sided and you need to count them on the server) you might want to use php or such where you can simply output a number into the html/js.

If you use php or such you might as well just use it to handle the url redirection as well.

A button / link redirects to
which contains

<?php //there can't be anything before this.
//No space, no linebreak, no html, due to the header redirect!
{$counter=fopen("count.txt", "a");}
{$counter=fopen("count.txt", "r+");}

else if($filedo==2){$goto="http://url.com/pageorsuch222.htm";}
else if($filedo==3){$goto="http://url.com/pageorsuch333.htm";}
else {
// RESET counter
// if all adresses have been accessed to restart
// (if you want)


header('Location: '.$goto);


...or something like that.

09-24-2008, 06:22 PM
THanks for the reply - would I have to create a txt file as well? and what would it contain. Also is it possible to do this in ASP? - when I create the file 'goaround.php' with the above code and link to it, it always taked me to URL1 only?

10-01-2008, 04:37 PM
Ok I had to update the permissions in the server for count.txt and it works but only for 10 urls. Is there a way to add more than 10 urls -
count.txt gets stuck with its value of 10 and keeps going to the same url over and over after the initial round.

10-07-2008, 05:24 PM
It is possible to do it in ASP, but I don't know ASP (nor do any of the other regulars here, insofar as I'm aware). If your server is limited to ASP, I suggest you ask for an upgrade — since the release of ASP.NET, ASP is completely obsolete, as are all the languages that use it.

10-08-2008, 01:16 PM
You can use exactly the code described in the original thread, but instead of
<?php include("countclicks.inc.php");
$pages = array(
$href = $pages[floor(getClicks() % count($pages))];
<!-- ... stuff ... -->
<a href="<?php echo($href); ?>">Click Here</a>use
<?php include("countclicks.inc.php");
$pages = array("pageone.php",

header(sprintf('Location: %s/%s',
$pages[floor(getClicks() % count($pages))]));
?>... to automatically redirect the user to the appropriate page without having to click anything.