Tracking new sessionsThe server is nice enough to tell us when a new session is created by calling a function in your global.asa file, Session_OnStart( ).If you don't have a global.asa, just create one - there's nothing magical about the file. A simple example is shown below: <script language=JavaScript runat=server>
function Session_OnStart ( )
{
// you must lock the global Application object
// when writing to it - ok to read without lock
Application.Lock ( );
// one more active user
Application ( 'ActiveUsers' )++;
Application.Unlock ( );
}
</script>
|
In this example, as on my site, I use the Session_OnStart( ) function to increment a count of how many users are currently on my site, or more accurately how many active sessions there are (you'll see in a minute that there are always more active sessions than users on your site...). There are no restrictions on what you can do in this function - you could initialize some Session variables in here, connect to your database, send emails - whatever. Part 4: Ending a session... |