A complete banner advertising system

Serving the ads

In Part 1, I loaded the ads for the day into Application variables for fast database-free access. Now I'll use those variables to display the ads:

// ============================================
// show the next available advertisement
// ============================================
function ShowAd ( )
{
   var nBanners = Application ( 'TotalBanners' );

   if ( !nBanners )
      return;

   // increment banner counter
   Application.Lock ( );

   if ( ++Application ( 'CurrentBanner' ) >= nBanners )
      Application ( 'CurrentBanner' ) = 0;

   Application.Unlock ( );

   // output banner html
   Out ( '<center>' + Application ( 'Banner' + Application ( 'CurrentBanner' ) ) + '</center>' );
}

This code is in utils/banners.asp. Calling the ShowAd( ) function outputs the HTML that I stored away in the Application variables earlier. The first step is to make sure I have some ads stored - if not then the function returns, having done nothing.

Next the Application is locked so I can increment yet another Application variable - "CurrentBanner". This variable is incremented until it is greater than the maximum number of banners, then it is reset to start again from zero. I then reference the relevant Application variable to output the banner code. "Banner0", then "Banner1", etc.

This is a very simple banner rotation system! It currently allows no weighting, no zones and takes no notice of the user watching or the page it is displayed on. All these things can change if demand warrants it of course!

Now let's go back and investigate BannerCounter.asp - the file that counts impressions and manages the clickthroughs.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Anyone who considers arithmetic methods of producing random digits is, of course, in a state of sin.” - John von Neumann