Hi...
I've got a quick question about rotating images. I'm working on a site where I have a banner across the top that I want to display a different image on a regular basis when the user browses to the site and / or while they are browsing the site.
I found a good peice of PHP code that works great... but it changes the image every time the browser either refreshes the same page or whenever a link is clicked and a new page comes up.
What I'd like to be able to do is have the code do one of two things...
Select the image randomly when the user first comes to the site and then stick with that same image throughout the entire session, or
Have the image rotate only so many refreshes or so many page links... like have it refresh after 10 link changes or 10 refreshes.
I'm not sure how to do this (or really even where to begin actually). The code I have now is as follows:
$dir=opendir("headers/");
$pattern="\.(gif|jpg|jpeg|png|bmp|swf)$";
if(!$dir) {
die("Failed to read directory");
}
$s=readdir($dir);
$count="0";
$image;
while($s) {
if(ereg($pattern, $s)) {
$image[$count]=$s;
$count++;
}
$s=readdir($dir);
}
closedir($dir);
// Display Image //
$limit=count($image);
$limit--;
$randNum=rand(0,$limit);
$directory = "headers/";
... and then I simply put the variables into the background image field of the table I'm using to display it in...
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="100%" height="100" align="right" valign="middle" background="<?php echo "$directory$image[$randNum]"; ?>">
<div align="center">
Any help would be greatly appreciated. The main reason I'd like to do this is to save on bandwidth... the background images are 1600 pixels wide by 300 high because I needed the image to stretch across the length of the page regardless of the user's browser window size.