I have a problem using an application variable in my global.asa. All other variables seem to work just fine. I don't think that the problem is in my code, so I wonder what can be the problem. ActiveUsers is the variable that causes problems ; In the beginning it works very well, but when a user visits my site, it (sometimes) jumps more than one number (even 17!). Working offline, the ActiveUsers-var doesn't immediately decrement when a users ends the session. This is my code:
On another page I increment the page hits (but this doesn't involve the ActiveUsers variable):
For a look at the numbers goto -> SITE-INFO (site for the moment just in Dutch, sorry ;-)
Code:
<SCRIPT LANGUAGE="VBScript" RUNAT="Server">
SUB Application_OnStart
Application.Lock
' number of users currently on the site
Application ( "ActiveUsers" ) = 0
' number of users on the site today
Application ( "UsersToday" ) = 0
' total number of users on the site
Application ( "TotalUsers" ) = 0
' number of pages viewed today
Application ( "PagesToday" ) = 0
' total number of pages viewed
Application ( "TotalPages" ) = 0
' remember todays date
Application ( "Today" ) = date()
' date since startup
Application ( "DateSince" ) = date()
Application.Unlock
END SUB
SUB Application_OnEnd
END SUB
SUB Session_OnStart
' Session.timeout = 15
Application.Lock
' one more active user
Application ( "ActiveUsers" ) = Application ( "ActiveUsers" ) + 1
' total users and total pages + 1
Application ( "TotalUsers" ) = Application ( "TotalUsers" ) + 1
' is it a new day?
nDate = Date()
if Application ( "Today" ) = nDate then
' same day, so increment users today
Application ( "UsersToday" ) = Application ( "UsersToday" ) + 1
else
' new day, so restart count
Application ( "Today" ) = nDate
Application ( "UsersToday" ) = 1
Application ( "PagesToday" ) = 1
end if
Application.Unlock
END SUB
SUB Session_OnEnd
Application.Lock
' one less active user
Application ( "ActiveUsers" ) = Application ( "ActiveUsers" ) - 1
Application.Unlock
END SUB
</script>
On another page I increment the page hits (but this doesn't involve the ActiveUsers variable):
Code:
<% response.buffer = true %>
<% Application.Lock %>
<% Application("PagesToday")=Application("PagesToday")+1 %>
<% Application("TotalPages")=Application("TotalPages")+1 %>
<% Application.Unlock %>