Hello friends, am having some advert banners to this play on my site. i have written the script that will randomly select the banner, but the problem is that at the end of the day some banners are displayed more that others eg. at the end of a day, a banner might have been displayed 300 times while another will just be displayed 70 times. Pls what can i do to randomly select the banners but at the end of each day, all the banners will have been displayed at the number of time or the difference in the number of times displayed will not be much. code/syntax for this will be appreciated. regards
It would help if we knew what your working with... but just off the cough if your using rand() try using mt_rand() instead as a better randomiser
Might be this code give you some help to display banners at equal times per day <?PHP /* random( $max integer ) Returns a random number between 0 and $max-1; */ FUNCTION random( $max ) { $x = RAND(); $y = GETRANDMAX(); $r = $x / $y * ($max -1 ); $r = ROUND( $r++ ); RETURN $r; } /* Read the directory, add all "banner*" files with to the array */ $i = 0; $d = DIR( "."); whle($entry=$d->read()) IF (SUBSTR($entry,0,6) == "banner") $array[$i++] = $entry; $d->close(); /* pick a banner at random */ $r = random( $i ); /* Send a no-cache header, and the gif type header, and output the file. */ HEADER( "Pragma: no-cache" ); HEADER( "Expires: Monday 01-Jan-80 12:00:00 GMT" ); HEADER( "Content-type: image/gif"); PASSTHRU( "cat $array[$r]" ); ?> Code (markup):
Have you considered adding a section that connects to a database? or writes to an external file, counting the impressions, and if impressions are more than the other banners, changing the banner, and updating the count. Then all you have to do is arrange to reset your counts each day (or specified time period)