Forum Moderators: coopster
The only problem with a current requirement is that the script rotates on every page load. I would like to be able to rotate like every "X" days.
The script I have now:
$banners_array = array
(
'tip1.php',
'tip2.php',
'tip3.php',
'tip4.php',
'tip5.php'
);
$i = array_rand($banners_array, 1);
$banner = $banners_array[$i];
include_once $banner;
How could this code be rewritten?
Base the index on the current day number
$RotateEveryXDays = 3; // Every 3 days another banner
$banners_array = array
(
'tip1.php',
'tip2.php',
'tip3.php',
'tip4.php',
'tip5.php'
);
$DayNr = time() / 86400; // Get day number (86400 = # seconds per day)
$BannerNr = $DayNr / $RotateEveryXDays; // WHich banner to use for this day
$i = $BannerNr % count($banners_array); // But limit to number of available banners
$banner = $banners_array[$i];
include_once $banner;
Regards,
Arjan
Thanks so much.
I'm kind of a dummy, so may I assume that the only value I need to change is the '3' in order to set the rotation?
$RotateEveryXDays = 3; // Every 3 days another banner
$banners_array = array
(
'tip1.php',
'tip2.php',
'tip3.php',
'tip4.php',
'tip5.php'
);
$DayNr = time() / 86400; // Get day number (86400 = # seconds per day)
$BannerNr = $DayNr / $RotateEveryXDays; // WHich banner to use for this day
$i = $BannerNr % count($banners_array); // But limit to number of available banners
$banner = $banners_array[$i];
include_once $banner;
I will work my way through this one line at a time and try to learn a little bit more about PHP .. onward and upward. :)
One thing I am trying is alternating a few affiliate text links vs a block of Adsense code.
In another case I want to alternate several different Adsense blocks .. partly for testing, partly for ad blindness.
<?php include "files/".date('d').".txt" ; ?>
and fill the files/ folder with files from 01.txt to 31.txt and use odd files to Adsense and even to links (or whatever you want). Anyway yo must write/copy and rename the 31 files. The easy way is using the copy command and the old batch files.