SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Creating Counters with ASP
By Scott Isaacs

With ASP, adding custom counters to your web-page is a very simple task. In this article, we show you how to automatically count what browser your visitors are using and how many active visitors are currently on the site. We will count how many visitors are using Internet Explorer, how many are using Netscape Navigator, and how many are using another browser. You will also see how easy it is to extend the counter script to easily count other aspects of your visitors (eg., browser version, platform, etc.).

Our counters rely on the session capabilities of ASP. Each time a user visits the site, ASP generates a unique session. This session object represents the user's entire visit. Session's work by creating a random identifier that is stored in a cookie on the client's machine on their first visit to an ASP page on your site. This identifier is valid for just the user's visit and will eventually expire (customizable by the web-site but usually around 20 minutes after the last page the user visits).

When the user first visits an ASP page (first visit is identified by the lack of a valid session cookie), a session is created. When the session is created, an event is fired in the global.asa file. This session_onstart event is where we will create and increment our counters.

Next we show you how add a visitor counter.