Many people have tutorials out there that allow you to count the number of active users online with the use of the global ASA file; however, they do not show you the user's location and "what they are doing".
i.e, going to your users_online.asp page may show the following:
- user J.Buttafucco is viewing the guestbook (/dev/guestbook.asp)
- user A.Fischer is deleting a guestbook entry (/dev/guestbook_delete.asp)
- user T.Harding is beating people up (/dev/beat_peeps_up.asp)
![](/Downloads/Tutorial_online_users_3.zip/gr.gif)
![](/Downloads/Tutorial_online_users_3.zip/bc.gif)
![](/Downloads/Tutorial_online_users_3.zip/gr.gif)
![](/Downloads/Tutorial_online_users_3.zip/gr.gif)
The Include File
Ok. Next, we need to include an include (bad grammar, so sue me) EVERY PAGE
NEEDS TO HAVE AN INCLUDE REGARDLESS OF WHETHER IT WILL ACCESS A DATABASE OR
NOT. We'll call this file myInclude.asp
<%
MM_connection_STRING
= "Trusted_Connection=yes; Driver={SQL Server}; Server=servername; Database=databasename; UID=username; PWD=password"
%
>
<%
Sub LogActiveUser
MM_rsKeyConnection
=MM_connection_STRING
MM_dupKeyUsernameValue
= CStr(
Session.SessionID)
MM_dupKeySQL
="SELECT fldSessionID FROM dbo.tblActiveUsers WHERE fldSessionID='" & MM_dupKeyUsernameValue
& "'"
MM_adodbRecordset
="ADODB.Recordset"
Set MM_rsKey
=Server.CreateObject(MM_adodbRecordset)
MM_rsKey.ActiveConnection
=MM_rsKeyConnection
MM_rsKey.Source
=MM_dupKeySQL
MM_rsKey.CursorType
=0
MM_rsKey.CursorLocation
=2
MM_rsKey.LockType
=3
MM_rsKey.Open
If Not MM_rsKey.EOF
Or Not MM_rsKey.BOF
Then
Else
MM_editQuery
= "insert into dbo.tblActiveUsers (fldSessionID, fldUsername, fldLocation, fldDoing) values ('" & Session.SessionID & "', '" & Session(
"person")
& "', '" & Session(
"location")
& "', '" & Session(
"doing")
& "')"
Set MM_editCmd
= Server.CreateObject(
"ADODB.Command")
MM_editCmd.ActiveConnection
= MM_connection_String
MM_editCmd.CommandText
= MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End If
MM_rsKey.Close
End Sub
Sub UpdateActiveUser
MM_editQuery
= "update dbo.tblActiveUsers set fldLocation = '" & Session(
"location")
& "', fldDoing = '" & Session(
"doing")
& "' where fldSessionID = '" & Session.SessionID & "'"
MM_editConnection
= MM_connection_STRING
Set MM_editCmd
= Server.CreateObject(
"ADODB.Command")
MM_editCmd.ActiveConnection
= MM_editConnection
MM_editCmd.CommandText
= MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
End Sub
Sub LogOutActiveUser
MM_editQuery
= "delete from dbo.tblActiveUsers where fldSessionID = '" & Session.SessionID & "'"
MM_editConnection
= MM_connection_STRING
Set MM_editCmd
= Server.CreateObject(
"ADODB.Command")
MM_editCmd.ActiveConnection
= MM_editConnection
MM_editCmd.CommandText
= MM_editQuery
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
Session.Abandon
End Sub
%
> ![](/Downloads/Tutorial_online_users_3.zip/gr.gif)
![](/Downloads/Tutorial_online_users_3.zip/bc.gif)
![](/Downloads/Tutorial_online_users_3.zip/gr.gif)
![](/Downloads/Tutorial_online_users_3.zip/gr.gif)
Comments
Great
Great tutorial. Just one thing would have make things lot easier for the newbies. I can imagine that volks will have some problems in implementing the script so why not provide them the files and the database. Then things will be lot more easier to understand.
Anyways thanxalot finally i got it workin, was lookin for this for a long time.
RE: Great
Great??
I don't even know why its rated 4.7?? It doesnot work. There are many errors. I am working on it if somebody sorted out then please let me know.
You must me logged in to write a comment.