Learn how to use global.asa to display the number of users visiting your site. This tutorial can be broken down into two sections, global.asa, and numvis.asp. Before you can begin this tutorial, make sure your host supports global.asa.
GLOBAL.ASA
Global.asa is defined as an optional file that defines functions, variables, and methods that are accessible by every ASP page within the application.The global.asa file is often used to define and proccess session-specific variables, which is its function in this tutorial. Global.asa can not be written in ASP, so no tags in this file, here's the file:
-
Sub Application_OnStartApplication("numvis")=0End SubSub Session_OnStartApplication.LockApplication("numvis")=Application("numvis") + 1Application.UnLockEnd SubSub Session_OnEndApplication.LockApplication("numvis")=Application("numvis") - 1Application.UnLockEnd Sub
English: whenever a user visits the site (triggering a session, Session_OnStart), the server adds one to the number of users, and whenever that user leaves (ending the session Session_OnEnd), the server subtracts one from the number of users. Application_OnStart applies only to when the server is started.NUMVIS.ASPThis file will display the number of visitors online like so:
-
There are online now!
Recent Comments