Ok, I needed to dispaly One banner per-page-view, and start at the beginning when I reached the last banner. (Which will always be no greater than 10.)
The only thing about this was, I couldn't figure out how to store and keep track of page counts without use of a database or a flat file. So I did it flat-file, and there's probably an easier way. While this script works just fine, maybe some one has an an idea that would be easier and faster?
<?php
/* Counting Page Hits to rotate the banners, Store it in a file. */
$store = "track.dat";
if(file_exists($store))
{
$fp = fopen($store, "r+");
flock($fp, 1);
$count = fgets($fp, 4096);
$count += 1;
fseek($fp,0);
fputs($fp, $count);
flock($fp, 3);
fclose($fp);
}
else {
/* If $store cannot be opened, alert some one. */
print "Err.";
}
/* Calling Banners in Sequence, when we reach the last banner, restet the tracker file */
$pos = file_get_contents('track.dat');
$limit = 10;
$reset = 0;
if ($pos >= $limit) {
$fp = fopen($store, "w");
fputs($fp, $reset);
fclose($fp);
}
echo "$pos \n<br>";
require_once('track.dat');
?>
Test page.
<?php
/* Banner Array */
$advert = array(
"0" => "image1",
"1" => "image2",
"2" => "image3",
"3" => "image4",
"4" => "image5",
"5" => "image6",
"6" => "image7",
"7" => "image8",
"8" => "image9",
"9" => "image10"
);
$pos = file_get_contents('track.dat');
print $advert[$pos];
?>