...

View Full Version : How do i make a different ad come up when someone refreshes the page?



bigcasey123
05-18-2012, 09:08 PM
You know how google has different ads everytime you go to a page? Well i want to do the same thing. I got two banners and i want one to change to the other banner when someone refreshes the page.

Old Pedant
05-18-2012, 11:42 PM
Use cookies. It's not perfect, because a user could turn off cookies, but that's rare enough you don't need to worry about it.

So just check for the cookie and, if it is not there, pick an ad at random. Then "remember" the ads the user has seen in the cookie. If the cookie is there, then just pick a random ad the user hasn't already seen.

Old Pedant
05-19-2012, 01:53 AM
On the next page load, start from step 2.

Ummm...actually, since it's always the same page being loaded, you won't have any choice but to start from step1. But that's okay, because if you didn't, then you wouldn't have any ads to display.

*********

If you are concerned about users who don't have cookies enabled, then instead of pulling the ads sequentially from the array, you would pull them randomly. And in the cookie you would keep a list of *all* the ads that have so far been displayed, so that you could remove them from the array before picking one at random. When the array is empty, you just start all over: clear out the list and pick any of them at random.

Philip M
05-19-2012, 07:39 AM
You know how google has different ads everytime you go to a page? Well i want to do the same thing. I got two banners and i want one to change to the other banner when someone refreshes the page.

FWIIW, many people delete their cookies at frequent intervals.

Rather than cookies you could display the banner based on whether the number of milliseconds at page load was odd or even. That would give a 50% chance of a new banner.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum