Forums

This topic is locked

One last time.... Users Online Advanced

Posted 13 Jul 2002 06:53:34
1
has voted
13 Jul 2002 06:53:34 aegis kleais posted:
If someone could show how, or even an article that shows, how you can get a script that can poll all active sessions (by sessionID?) and their respective data.

If I can poll individual data, I can make a page saying:

User 1 is VIEWING NEWS FEED (/dev/news_feed.asp)
User 43 is LOGGING OUT (/dev/logout.asp)
.......

I wish there was an object that contained the SessionIDs of all active Sessions. Say it's called SessMgr. If there was a way I could then create a recordset of all SessioNIDs in SessMgr. From there I would just create

<%= SessMgr(i).Session("username" & " is " & SessMgr(i).Session("doing" & "(" & SessMgr(i).Session("location" & "" %>

Of course, this means that on the first page I'd need to set the Session("username" And on all pages, I would need to change the Session Variables ("doing" and ("location" to what the user was doing. It would be nice if something like this existed, because the only other way I see possible, would involve updating/deleting all this information to a db table each time the user requests a new page.

But hey, I'm using SQL and no more then 50 people'll be using this thing at once, so that won't be a problem.

Anyone up for this one?

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])

Replies

Replied 13 Jul 2002 17:49:24
13 Jul 2002 17:49:24 aegis kleais replied:
Ok, I'm gonna post POSSIBLY how to do this, and hopefully get some feedback from the forums...

PROCESS
Ok, we're gonna be storing the user's name, location, and what they are doing. All of these are session variables.

Session("person" = Session("MM_Username"
' This sets person to the name they logged into the system with (secure system)
Session("location" = Request.ServerVariables("SCRIPT_NAME"
' This will return the absolute path to the user's current location
Session("doing" = "Depends."
' Each page will individually set doing to what the nature of the page is intended for. In this way, people on the front page would have:
Session("doing" = "Looking at the front page"

So in the above example, the desired output for all active users is:

aegiskleais is looking at the front page (/mywebsite/frontpage.asp)

Here's the current concerns. A database could possibly hold all active users in tblActiveUsers, but a procedure would have to be placed in the global asa's Session_OnStart and Session_OnEnd that would both write the new user on Session Start and remove that user on Session End. This is ok to start with, but Session OnStart and OnEnd are not called for everytime the user changes pages (which changes their location and doing status)

More then likely we'll need a database and a few custom procedures in the global.asa file or an include. Lets see the following code:

global.asa
------------------------------------------

<script language=vbscript runat=server>

' =========================================
' = Declare and create the database connection outside
' = other subs so that they inherit it
' =========================================

set rsActiveUsers = Server.CreateObject("ADODB.Recordset"
rsActiveUsers .ActiveConnection = "Trusted_Connection=yes; Driver={SQL Server}; Server=servername; Database=databasename; UID=userID; PWD=password"
rsActiveUsers .Source = "SELECT * FROM dbo.tblActiveUsers"
rsActiveUsers .CursorType = 0
rsActiveUsers .CursorLocation = 2
rsActiveUsers .LockType = 3
rsActiveUsers .Open()
rsActiveUsers _numRows = 0

Sub LogActiveUser
' =========================================
' = This sub is called to add the user's initial information
' = to the database. First, insert new record if SessionID
' = does not exist. Insert Session("person",
' = Session("location", Request.ServerVariables("SCRIPT_NAME",
' = and Session("doing" into database
' =========================================
End Sub

Sub UpdateActiveUser
' =========================================
' = This sub us called each time the user requests a new
' = page. It makes sure that the location and the doing
' = status are correctly set.
' =========================================
End Sub

Sub LogOutActiveUser
' =========================================
' = This sub is used to remove an expired user's information
' = from the database. Search via the current SessionID
' = if found, remove it from the database. This should leave
' = it so that only active Sessions are remaining in the
' = database.
' =========================================
End Sub

Sub Session_OnStart
Call LogActiveUser
End Sub

Sub Session_OnEnd
Call LogOutActiveUser
End Sub

</script>

--------------------------------------------------------------------------------------

When I need to showcase the data, I'll just create a recordset from tblActiveUsers; no filtering, and possibly a username sort alphabetically, which should then show all the info.

Anyone see a problem with this method offhand?

Aegis Kleais
New Media Web Developer
(DWMX : IIS5.1 : SQL2K : WXP : ASP[VB/JS])

Reply to this topic