The following code rotates 2 web pages, so that visitor 1 will see index0.htm, visitor 2 will see index1.htm, visitor 3 see's index0.htm and so on. To avoid a visitor seeing a different page by clicking refresh or some other means, it sets a cookie with a value of 0 or 1.
The page seems to work fine - almost. There seems to be slighly more calls to index1.htm than index0.htm. And I can't work out why.
Any suggestions?
The code below is stored in index.php.
Thanks,
Jon
<?php
//Simple PHP headline swapper
//Check for cookie
$ICCTestCode = $HTTP_COOKIE_VARS["ICCTestCode"];
if ($ICCTestCode && ($ICCTestCode != "")) {
include("index".$ICCTestCode.".htm");
} else {
if (file_exists('count.inc'))
{
//if file exists..read the last supplied file.
$fil = fopen('count.inc', 'r');
$dat = fread($fil, filesize('count.inc'));
fclose($fil);
}
else
{
//if it doesnt exist. create one.
// in ur code , if file doesnt exist, it wont display any headers. i have corrected it here.
$fil = fopen('count.inc', 'w');
fwrite($fil, 0);
fclose($fil);
$dat = 0;
}
//Set cookie
setcookie("ICCTestCode", $dat, time()+345600);
//using include to display the appropriate page:
$filename = 'index'.$dat.'.htm';
include("$filename");
// my approach for rewinding value of dat..
if($dat > 0) {
$dat = 0;
}
else
{
$dat++;
}
//now write in the new value...
$fil = fopen('count.inc', 'w');
fwrite($fil, $dat);
fclose($fil);
}
?>