Is this what you want?
if( isset( $HTTP_COOKIE_VARS['BANNER_NUMBER'] ) )
{
$banner = $HTTP_COOKIE_VARS['BANNER_NUMBER'];
$banner = ($banner + 1) % 3;
}
else
{
$banner = rand(0,2);
}
setcookie( 'BANNER_NUMBER', $banner, time()+(60) );
?>
When someone first visits the page, they get a rand() banner. Then each time they reload it after they get the next banner in series (you'd want to change the (60) in the setcookie to something longer, like (60*60*24*30)).
Demo:
http://omega0.xepher.net/stuff/banners.phpIf you want to be really tricky, and randomize it further, you could do something like this:
if( isset( $HTTP_COOKIE_VARS['BANNER_ARRAY'] ) ) {
$banners = split( '#', $HTTP_COOKIE_VARS['BANNER_ARRAY'] );
}
else {
$banners = array(0,1,2);
}
if( count($banners) == 1 ) {
$banner = $banners[0];
$newbanners = '0#1#2';
}
else {
shuffle( $banners );
$uns = $banners;
$banner = array_shift($banners);
$newbanners = array_shift($banners);
while( $temp = array_shift($banners) )
{
$newbanners = $newbanners . '#' . $temp;
}
}
setcookie( 'BANNER_ARRAY', $newbanners, time()+(60*60) );
What this does, is store a list of undisplayed banners in a cookie like 1#2#3. On each load, it mixes up the list, pulls of the top one to display now and then stores the remaining choices in a cookie. So the viewer can't get the first one again until all the others have been viewed, but he won't get them in the same order every time (but you could get a repeat like this: 1,2,3,3,1,2 since after the 1,2,3 they've all been viewed and it could very well start with 3 on the next run through of the list. With a large list though, this becomes rare, and you could modify the code to exclude the last one when reloading $newbanners with the full list).
Demo:
http://omega0.xepher.net/stuff/banners2.phpIf you don't care about tracking each user individually (or care about those people who turn off cookies), you can do something like this:
$f = fopen("bannerlist.txt","r");
$banner = fgets($f);
fclose($f);
$f = fopen("bannerlist.txt","w");
$next = ($banner + 1) % 3;
fputs( $f, $next );
fclose($f);
?>
All this does is store the value of what the next banner should be in a text file and does open, read, increment, save on each load. And you could always combine #2 and #3.
Demo:
http://omega0.xepher.net/stuff/banners3.phpThe text file is:
http://omega0.xepher.net/stuff/bannerlist.txtSo, does any of this do what you want?
And does anyone know a simpler way for what I did in #2? I can't believe that (in a perl-like language no less) there wouldn't be an easy array->string converter.