Counting visters with the global.asa file.

Drew 0 Tallied Votes 130 Views Share

This is a neat little script that will tell you how many active users
you have on your site. You do need a webhost that supports the
global.asa file! Most free hosts dont.

Code From: http://www.iportalx.net

First lets create the global.asa file that counts the active users.
Again, your host must support global.asa files or this will not work!

[code]
<script language="vbscript" runat="server">

Sub Application_OnStart
       'Set the active users to zero
       Application("ActiveUsers") = 0
End Sub

Sub Application_OnEnd
        'no code is needed here
End Sub

Sub Session_OnStart
       Session.Timeout = 5
       Session("Start") = Now
       Application.Lock

       'Add one to the active users when the person first visits
       Application("ActiveUsers") = Application("ActiveUsers") + 1

       'this adds 1 to the number of active users when a new user hits
       Application.unlock
End Sub

Sub Session_OnEnd
       Application.Lock

       'Subtract one after the user leaves your website
       Application("ActiveUsers") = Application("ActiveUsers") - 1
      
       'this subtracts 1 from the number of active users when a new user leaves
       Application.unlock
End Sub

</SCRIPT>
[/code]

Now that the global.asa file is created you can include the following any where on your ASP pages.

[code]
You are one of <b><% = Application("ActiveUsers") %></b> current users
[/code]

Note: You do not need to include the global.asa file!

Now upload the global.asa file to the ROOT directory of your website
(that would be the very first directory that your website looks in when
you visit you websites URL).