Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

See anything wrong with this?

Posted 01 Aug 2002 20:00:21
1
has voted
01 Aug 2002 20:00:21 aegis kleais posted:
Ok, I've one upped my USERS ONLINE system so that it's more bug free and will, when done, make a tutorial for UDZone.com But I have one last problem, and am now looking to the forum to see if I can get it answered.

Here's the deal. So far, I've successfully been able to maintain a table called dbo.tblActiveUsers (MS SQL) and when a person first starts their visit (open session) they are successfully added to this table. This table is also updated successfully everytime they go to a new page (it updates the fields : fldLocation and fldDoing)

The problem is getting it to delete users who either (A) logout or (B) have their session expire.

On my logout page, I have the following :

<%
Session("location" = Request.ServerVariables("SCRIPT_NAME"
Session("doing" = "logging out"
Call UpdateActiveUser
Call LogOutActiveUser
%>

I also have an include on that page (for the Call Sub Procedures) Those lines of code are as follows:

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.
' =========================================
MM_editQuery = "update dbo.tblActiveUsers set fldUsername = '" & Session("person" & "', fldLocation = '" & Session("location" & "', fldDoing = '" & Session("doing" & "' where fldSessionID = '" & Session.SessionID & "'"
MM_editConnection = MM_csSQLLoki_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
Session.Timeout = 1
Session("person" = NULL
Session("password" = NULL
Session.Abandon
End Sub

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

Where it says MM_csSQLLoki_STRING, I've provided a valid connection string (which I won't post for security reasons and such), but needless to say, it works fine, allowing me to update, insert and delete from all tables perfectly)

So the beef here is with the logout. I set the Session.Timeout to 1 minute and then set certain Session Variables to NULL for security, and finally Abandon the session. Now, in the Global.ASA I have the following happen on Session_End (which, to my knowledge would either happen NOW, or when the user's session expires)

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

Sub Session_OnEnd
Application.Lock
Application("usersOnline" = Application("usersOnline" - 1
Application.UnLock
MM_editTable = "dbo.tblActiveUsers"
MM_editColumn = "fldDoing"
MM_editValue = "logging out"
MM_csSQLLoki_STRING = <i>[removed, but is a valid connection string]</i>
MM_editQuery = "DELETE FROM" & MM_editTable & " WHERE " & MM_editColumn & " = " & MM_editValue
MM_editConnection = MM_csSQLLoki_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

So to my understanding, this should remove anyone who's fldDoing table contains logging out (this SHOULD work for people who use the LOGOUT button, but I'm still looking as to get a catch all if the session just expires) I think I can't use any session information in the Session_OnEnd Sub because the session already expired. So I've used constants and variables.

Any comments?

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

Reply to this topic