PDA

View Full Version : interactive button for round robin



shawnl55
12-10-2005, 01:19 AM
Need help on a script that will set up an interactive button so when the first person that hits it will be directed to one page, and the next hit will be directed to another page, then back and forth each hit.
Thank You
Shawn :confused:

Twey
12-10-2005, 10:13 AM
Server-side only, I'm afraid.
countclicks.inc.php:
<?php
$newline = "\n"; // Newline symbol for the server. Likely values are "\n" for *n?x or "\r\n" for Windows.
$filename = "regcount.dat"; // Name of the file in which to store number of registrants.

// Function to get the number of registrants.
function getClicks() {
global $filename, $newline;
return file_exists($filename) ? implode(file($filename), $newline) + 0 : 0;
}

// Function to increment the number of registrants.
function incClicks() {
global $filename, $newline;
$clickcount = getClicks();
$clickcount++;
$file = fopen($filename, "w");
fputs($file, $clickcount);
fclose($file);
}
?>At the top of your main page:
<?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>
On all the pages the link could go to:
<?php include("countclicks.inc.php"); incClicks(); ?>You must have PHP installed on your server to use the above code.