PDA

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



rroundrobin
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:
http://www.dynamicdrive.com/forums/showthread.php?t=6529

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!

schorhr
09-21-2008, 12:17 PM
Hello,
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.

Example:
A button / link redirects to
goarround.php
which contains


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

if($filedo==1){$goto="http://url.com/pageorsuch111.htm";}
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)
$filedo=1;
$goto="http://url.com/pageorsuch111.htm";
}


rewind($counter);
fputs($counter,$filedo);
fclose($counter);

header('Location: '.$goto);


?>


...or something like that.

rroundrobin
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?

rroundrobin
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.

Twey
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.

Twey
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(
"pageone.php",
"pagetwo.php",
"pagethree.php"
);
$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",
"pagetwo.php",
"pagethree.php");

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