By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,738 Members | 1,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,738 IT Pros & Developers. It's quick & easy.

Tracking logged in users and visitors

P: n/a
gil
I'm trying to track how many users are visiting a site and how may are
logged in, using application sessions like so:

Sub Session_OnStart
Session.Timeout = 20
Session("Start") = Now
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
End Sub

Sub Session_OnEnd
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock
End Sub
The problem is that I don't know whose session is ending, a logged in user
or a visitor and therefore can't decrement when one or the others session
ends.

Is it possible to identify the session that is ending by name so I can track
two different sets of data, one for visitors and one for users? What is a
good way to go about this consdering that users won't always click the
"logout" button when ending their visit?


Thank you



Jul 22 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
How about:

Sub Session_OnStart()
Application.Lock
Application("TotalUsers") = Application("TotalUsers") + 1
Application.Unlock
End Sub

Sub Session_OnEnd()
Application.Lock
If Session("Username") = "" Then
Application("Visitors") = Application("Visitors") - 1
Else
Application("RegisteredUsers") = Application("RegisteredUsers") - 1
End If
Application.Unlock
End Sub
And in your login code,

<%
'''code for login
Application.Lock
Application("RegisteredUsers") = Application("RegisteredUsers") + 1
%>

Ray at work
"gil" <gi*@nospam.thankyou> wrote in message
news:uS**************@TK2MSFTNGP10.phx.gbl...
I'm trying to track how many users are visiting a site and how may are
logged in, using application sessions like so:

Sub Session_OnStart
Session.Timeout = 20
Session("Start") = Now
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") + 1
Application.UnLock
End Sub

Sub Session_OnEnd
Application.Lock
Application("ActiveUsers") = Application("ActiveUsers") - 1
Application.UnLock
End Sub
The problem is that I don't know whose session is ending, a logged in user
or a visitor and therefore can't decrement when one or the others session
ends.

Is it possible to identify the session that is ending by name so I can
track
two different sets of data, one for visitors and one for users? What is a
good way to go about this consdering that users won't always click the
"logout" button when ending their visit?


Thank you



Jul 22 '05 #2

P: n/a

"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:%2****************@TK2MSFTNGP14.phx.gbl...
How about:

Sub Session_OnStart()
Application.Lock
Application("TotalUsers") = Application("TotalUsers") + 1
Application.Unlock
End Sub

Sub Session_OnEnd()
Application.Lock
If Session("Username") = "" Then
Application("Visitors") = Application("Visitors") - 1
Else
Application("RegisteredUsers") = Application("RegisteredUsers") - 1
End If
Application.Unlock
End Sub
And in your login code,

<%
'''code for login
Application.Lock
Application("RegisteredUsers") = Application("RegisteredUsers") + 1
%>

Ray at work

Ray,

on a similar theme I'd like to check for the existance of someone being
logged on. I posted a day or so ago and had a reply from Tom, and I've
looked at the FAQ but the global.asa and application stuff is new to me and
so this might be a little beyond my scope.

I'm trying to see if someone is logged on by checking to see if a session
exisits in their name, how would I go about this?

many thanks
Jul 22 '05 #3

P: n/a
Write the info to a database when they logon.

"Alistair" <ma**@alistairbremoveme.co.uk> wrote in message
news:10************@corp.supernews.com...

"Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
message news:%2****************@TK2MSFTNGP14.phx.gbl...
How about:

Sub Session_OnStart()
Application.Lock
Application("TotalUsers") = Application("TotalUsers") + 1
Application.Unlock
End Sub

Sub Session_OnEnd()
Application.Lock
If Session("Username") = "" Then
Application("Visitors") = Application("Visitors") - 1
Else
Application("RegisteredUsers") = Application("RegisteredUsers") - 1 End If
Application.Unlock
End Sub
And in your login code,

<%
'''code for login
Application.Lock
Application("RegisteredUsers") = Application("RegisteredUsers") + 1
%>

Ray at work
Ray,

on a similar theme I'd like to check for the existance of someone being
logged on. I posted a day or so ago and had a reply from Tom, and I've
looked at the FAQ but the global.asa and application stuff is new to me

and so this might be a little beyond my scope.

I'm trying to see if someone is logged on by checking to see if a session
exisits in their name, how would I go about this?

many thanks

Jul 22 '05 #4

P: n/a

<je**@removeemergencyreporting.com> wrote in message
news:u3**************@TK2MSFTNGP11.phx.gbl...
Write the info to a database when they logon.


yes I thought of this but most users don't logout, they just close the
browser and so the DB record would not get removed.
Jul 22 '05 #5

P: n/a
No, you remove the record when they log in again..typical setup

Jeff
"Alistair" <ma**@alistairbremoveme.co.uk> wrote in message
news:10*************@corp.supernews.com...

<je**@removeemergencyreporting.com> wrote in message
news:u3**************@TK2MSFTNGP11.phx.gbl...
Write the info to a database when they logon.


yes I thought of this but most users don't logout, they just close the
browser and so the DB record would not get removed.

Jul 22 '05 #6

P: n/a

<je**@removeemergencyreporting.com> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
No, you remove the record when they log in again..typical setup

Jeff
"Alistair" <ma**@alistairbremoveme.co.uk> wrote in message
news:10*************@corp.supernews.com...

<je**@removeemergencyreporting.com> wrote in message
news:u3**************@TK2MSFTNGP11.phx.gbl...
> Write the info to a database when they logon.
>


yes I thought of this but most users don't logout, they just close the
browser and so the DB record would not get removed.



and how is that going to show when they are logged in??

when they log in the first time, I write a record in the DB that shows they
are logged in, then they close the browser, and if they don't log in for
another week then the record showing them as logged in is wrong for a week!!

Jul 22 '05 #7

P: n/a
Alistair wrote:
and how is that going to show when they are logged in??

when they log in the first time, I write a record in the DB that
shows they are logged in, then they close the browser, and if they
don't log in for another week then the record showing them as logged
in is wrong for a week!!


That's the nature of the beast. Aaron describes a strategy for deleting
inactive users in an article at www.aspfaq.com, but even that is not
perfect. You have to realize that with a stateless protocol like http, there
is no way to know for certain how many users are logged in.

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #8

P: n/a
Exactly. With HTTP, there is NO guaranteed way to determine log out.

You can always implement logic that concludes that if a user has a login
record, but hasn't hit the database for an hour (or whatever), then they are
gone. Obviously this would imply that you would have to log every page hit
in the database.

Jeff

"Alistair" <ma**@alistairbremoveme.co.uk> wrote in message
news:10*************@corp.supernews.com...

<je**@removeemergencyreporting.com> wrote in message
news:u1**************@TK2MSFTNGP09.phx.gbl...
No, you remove the record when they log in again..typical setup

Jeff
"Alistair" <ma**@alistairbremoveme.co.uk> wrote in message
news:10*************@corp.supernews.com...

<je**@removeemergencyreporting.com> wrote in message
news:u3**************@TK2MSFTNGP11.phx.gbl...
> Write the info to a database when they logon.
>

yes I thought of this but most users don't logout, they just close the
browser and so the DB record would not get removed.


and how is that going to show when they are logged in??

when they log in the first time, I write a record in the DB that shows

they are logged in, then they close the browser, and if they don't log in for
another week then the record showing them as logged in is wrong for a week!!

Jul 22 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.