Jump to content

Creating Something that Rotates ad banners?


Gutspiller

Recommended Posts

Hello,

 

I am a php noob, but I am hoping somebody here can give me some sample code that will help me get some ad rotation going. I already have a script that randomly calls lines of code, but I don't want it to be random. Since the random could actually show one type of banner more than others, I would like it to be sequential.

 

This is possible without any database isn't it?

 

I am looking for something that is very simple and not a whole lot to it, and will load fast for my website.

 

If it helps, here is my random code I currently have that loads in an iframe and randomly picks between the two url pages which each contain the ad code from two different ad companies.:

 

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
<!--
Array.prototype.random = function () {return this[Math.floor(Math.random() * this.length)]}

Date.ONE_SECOND = 0;

url = ['http://www.mysite.com/includes/gameyanker.php', 'http://www.mysite.com/includes/cpmstar.php' ]



setTimeout('location = url.random()', 5 * Date.ONE_SECOND)
// -->
</script>

</head>

<body bgcolor="#EBE9EE" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" rightmargin="0">

</body>
</html>

 

Thanks for any help people can provide me with.

Link to comment
Share on other sites

This isnt a php question. but more of a Javascript problem as far as I can tell. you can use PHP to select a random number and depending on that number it will display a preticular banner. Altho it will only rotate the banner when the page is refreshed.

 

Personally I would use PHP and make only 1 banner load at a time. but itf you need a new banner every 5s then I suggest looking into javascript tick();

Link to comment
Share on other sites

I don't want the banner to refresh multiple times per page view, but I do want it to show different banners every time somebody visits a page where I have this code loading.

 

Like if 1 person visits 1 page. I want it to show banner1 once. I don't want it to reload that code and on that 1 page view show them banner1 and then later show them banner2.

 

I do however want it to show banner1 to userA and banner2 to userB.

 

Can this be done in php or would this be javascript as well?

Link to comment
Share on other sites

PHP is just fine for it. You can easier use sessions or a database to determine what it is.

 

Your line of thinking, while userA sees banner1 userB sees banner2 is hard to track and I would not suggest thinking like that. If you want this you would need a DB and chances are userA can see banner1 while userB sees banner2 but if userC comes on what is he going to see? If you have 50 users and only 10 banners, you have an issue if all users come on.

 

Instead if userA has seen banner1 show banner2 if seen banner 1 and 2 show banner3 etc. Then just reset the hasseen once they have seen the last banner.

 

Or better yet just do a random rotation works great too.

Link to comment
Share on other sites

Since you want it to rotate between users, you are going to have to store an array of possible banner choices, as well as a pointer, somewhere, be it flatfile or database.  That's the only way the script running for userB is going to be able to know that userA already saw banner1, so display banner2.  The pointer would point to the current element of array of possible banners.  When script is requested, it will pull the banner from that position, and move the pointer to the next position.  If you reach the end of the line, point it back to the beginning.  You would then use a session var to keep the script displaying the banner selected.

Link to comment
Share on other sites

i agree with premiso, you might want to abandon the thing about user1 seeing this banner and user2 seeing this banner. That can be very hard, instead try to just do it randomly.

 

Yeah, because my suggestion is nasa level rocket science.

 

haha well in all honesty... ;)

Link to comment
Share on other sites

Ah, you guys are making this harder than it has to be... or maybe I explained it poorly.

 

I don't care what banner userA and userB see, what I want is something that is more guaranteed to show the banners evenly to each user. It's that the random code is random, but there is nothing that says that random code doesn't keep displaying some of the same ad code over and over. I want each ad code to get equal "face time".

 

Hopefully this is a better explanation of what I am looking for.

 

I just don't want to show one ad code on my site more than another.

 

Can somebody give me the code that would do this? I want it to call individual files and those files are the ones that contain each of the different ad codes I have for that spot.

 

Any help would be greatly appreciated as I don't have any coding skills. :(

Link to comment
Share on other sites

$ads = array ('ad1','ad2','ad3','ad4','ad5');
$ad = array_rand($ads);

 

This will pick a random ad.  Overall, it will be evened out (the whole law of averages thing).  However, this does not guarantee that you will get a string of ad1 ad1 ad1 ad1 at some point in time.  But overall, it will be evened out.  The only way to guarantee that it will not randomly do something like ad1 ad1 ad1 ad1 is if you somehow keep track of what is being picked.

 

Now you say that if someone goes to the site, you want a random ad picked.  First thing you need to clarify is what you mean by "goes to the site."  For instance, you said you want the ad to stay the same if user refreshes the current page.  But what if he follows a menu link or whatever to another page?  Do you want it to show the same ad, or a new one, but make sure it's not the same one as before?  You can use sessions to track that. 

 

But now let's say user goes to your site, gets ad1.  He leaves and comes back a couple hours later or tomorrow or whenever.  Do you want to make sure that since he saw ad1 the last time he was there, that it will pick anything but ad1?  If so, you're going to have to throw a cookie into the mix.  Or a flatfile or db. 

 

And you still haven't really been clear on this: if userA gets ad1, do you want userB to not pick ad1, since it was just picked by userA?  If so, you're definitely going to have to go the flatfile or db route. 

 

So yeah...clarify what exactly you want to happen, because "I just don't want to show one ad code on my site more than another." isn't very specific. 

 

Also, fyi:

Can somebody give me the code that would do this?

 

That's not really what we're here for.  We'll point you in the right direction or help you fix bugs but if you want someone to do it for you, hire someone, because that's the sort of thing people get paid to do. 

 

 

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.