Jump to content

How do I code an ad to show up half the time?


Jeffro

Recommended Posts

My wife and I are working on a site and thought it would be fun to display her adsense 336 ad half the time and mine half the time (fully understanding that coding for a random 50/50 chance could mean a variance of 60/40, 70/30, etc.. at different times)

 

How could I display the following w/ php?....

 

"on page load ... present a 50/50 shot that either case 1 or case 2 happens... 

Case 1

show ad 1

 

Case 2

show ad 2"

use unix timestamp with modulus for a 50/50 split... timestamp measures the seconds passed since 1st jan 1970, so the ad would change depending on if the seconds were odd or even. i.e. 10001 would be ad1 and 10002 would be ad2. rough 50/50 split.

$time = time();
if ($time % 2) {
    echo "ad1";
} else {
    echo "ad2";
}

use unix timestamp with modulus for a 50/50 split... timestamp measures the seconds passed since 1st jan 1970, so the ad would change depending on if the seconds were odd or even. i.e. 10001 would be ad1 and 10002 would be ad2. rough 50/50 split.

$time = time();
if ($time % 2) {
    echo "ad1";
} else {
    echo "ad2";
}

 

 

What a cool ... and easy idea!  Thanks for the input! 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.