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"

Link to comment
Share on other sites

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";
}

Link to comment
Share on other sites

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! 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.