Jeffro Posted June 8, 2011 Share Posted June 8, 2011 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" Quote Link to comment https://forums.phpfreaks.com/topic/238736-how-do-i-code-an-ad-to-show-up-half-the-time/ Share on other sites More sharing options...
joel24 Posted June 8, 2011 Share Posted June 8, 2011 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/238736-how-do-i-code-an-ad-to-show-up-half-the-time/#findComment-1226773 Share on other sites More sharing options...
Jeffro Posted June 8, 2011 Author Share Posted June 8, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/238736-how-do-i-code-an-ad-to-show-up-half-the-time/#findComment-1226783 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.