Log in

View Full Version : Showing ads only to 20% percent of visitors. Or different ads to another 80% visitors



basketmen
07-31-2012, 08:03 AM
Hi guys, how to do this in a php file

Showing ads only to 20% percent of visitors. Or showing different ads to another 80% visitors

any way that can work, maybe using time intervals, like the visitors that visit the site at minute 0-12 only that show it, and visitors that visit the site at minute 13-59 is not. Or another methode

please help or share if you have, this should be easy enough and many people should need it, already googling it but still cant found it

djr33
07-31-2012, 08:12 AM
You need to determine how you want to divide the ads. You could do this by time (based on the current second of the current server clock time? By hour? Etc.), or you could do this by a rotation for each visitor and track it in a database.

Or the simplest version of this would be to use a random number. Based on your math:


<?php
if (mt_rand(1,5)===1) {
//show the ad!
}
else {
//alternative content, or omit this else block
}
?>