Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 CoverYourASP --> Managing banner ad clickthroughs --> Part 2

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
39 active users
961 visitors today
3333 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2010 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

One clickthrough per IP per day

The first idea I implemented was to only count one clickthough per IP address per day. I didn't want to use a database or file to store the IP addresses, and then search for them - that's a little over the top. So I had the idea that I'd use an Application variable - which would get emptied each day.

The BrandNewDay ( ) function

First I initialized some variables. This code was added to global.asa's Application_OnStart function - IIS calls this function automatically when the server starts up...

function Application_OnStart ( )
{
   Application.Lock ( );

   // remember todays date
   var d = new Date;
   Application ( 'Today' ) = d.getDate ( );

   // initialize new stuff in utils/Init.asp
   Application ( 'BrandNewDay' ) = 1;

   // a list of IP addresses that have clicked an ad
   Application ( 'ClickFromIP' ) = '';

   Application.Unlock ( );
}

...then I reset the BrandNewDay when the date rolled over (incidentally, I can also reset it manually by calling the BrandNewDay.asp page, which is sometimes handy. I'll leave you to look at that page):

function Session_OnStart ( )
{
   Application.Lock ( );

   // is it a new day?
   var d = new Date;

   if ( Application ( 'Today' ) != d.getDate ( ) )
      Application ( 'BrandNewDay' ) = 1;

   Application.Unlock ( );
}

Now I know when the day changed I modified utils/Init.asp so that a new BrandNewDay ( ) function gets called when this Application variable is set. I also cleared the Application ( 'ClickFromIP' ) variable that I'll use in a minute:

// ============================================
// anything that needs doing once per day!
// ============================================
function BrandNewDay ( )
{
   if ( Application ( 'BrandNewDay' ) == 1 )
   {
      Application.Lock ( );

      // clear the list if IP addresses that are ignored
      Application ( 'ClickFromIP' ) = '';

      Application ( 'BrandNewDay' ) = 0;

      Application.Unlock ( );
   }
}

Part 3: Application ( 'ClickFromIP' )...

Featured sponsor
My favorite resources

Tiki Statues - Tiki Masks - Tiki Totems


CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...