Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 Wat's wrong with this?
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

SubKamran
Junior Member

101 Posts

Posted - 13 May 2002 :  23:16:13  Show Profile  Visit SubKamran's Homepage  Send SubKamran an AOL message  Send SubKamran a Yahoo! Message
This is a code that's supposed to show active users and their info...unfortunately, it wont DELETE the records when the session ends...

Here's the code:


<object runat="Server" scope="Application" id="rstActiveUsers" progid="ADODB.Recordset">
</object>

<script language="VBScript" runat="Server">

Sub Application_OnStart()
' Selected constants from adovbs.inc
Const adInteger = 3
Const adVarChar = 200
Const adDate = 7

' Here I set up in memory active user recordset
' by adding the fields I want to it and defining
' their data types.
rstActiveUsers.Fields.Append "id", adVarChar, 255
rstActiveUsers.Fields.Append "username", adVarChar, 255
rstActiveUsers.Fields.Append "userlevel", adInteger, 1
rstActiveUsers.Fields.Append "ip", adVarChar, 15
rstActiveUsers.Fields.Append "browser", adVarChar, 255
rstActiveUsers.Fields.Append "OS", adVarChar, 255
rstActiveUsers.Fields.Append "Where", adVarChar, 255
rstActiveUsers.Fields.Append "started", adDate

' Next I open our recordset so that we can use it.
' That basically gets everything ready for our
' first user.
rstActiveUsers.Open
End Sub

Sub Session_OnStart()
' Set session timeout to 20 minutes
Session.Timeout = 10

' Set a session start time. This is pretty pointless,
' but it does ensure that we start a session and
' assign the user a session id and it can help
' troubleshooting if we ever need it.
Session("Start") = Now()

' Move to the end so records are added in order.
' Again not of any real importance, but it keeps our
' user table nice and orderly.
If Not rstActiveUsers.EOF Then rstActiveUsers.MoveLast

' Add a record and insert users data. I'm just
' storing some basic info, but naturally you're free
' to store whatever you want.
rstActiveUsers.AddNew

rstActiveUsers.Fields("id").Value = _
Session.SessionID

rstActiveUsers.Fields("UserLevel").Value = _
Request.Cookies("LoggedIn")("Level")

If Request.Cookies("LoggedIn")("Username") = "" Then
rstActiveUsers.Fields("username").Value = "Guest"
Else
rstActiveUsers.Fields("username").Value = _
Request.Cookies("LoggedIn")("Username")
End If
rstActiveUsers.Fields("ip").Value = _
Request.ServerVariables("REMOTE_HOST")

rstActiveUsers.Fields("browser").Value = _
Request.ServerVariables("HTTP_USER_AGENT")

rstActiveUsers.Fields("OS").Value = _
Request.ServerVariables("HTTP_USER_AGENT")

rstActiveUsers.Fields("Where").Value = _
Request.ServerVariables("URL")

rstActiveUsers.Fields("started").Value = _
Now()

rstActiveUsers.Update

' Now that we've got the information, all that's
' left is to display it. See test_page.asp for a
' demo. It includes the pages show_count.asp and
' show_users.asp which can also be used
' individually if desired.
End Sub

Sub Session_OnEnd()
' Selected constants from adovbs.inc
Const adAffectCurrent = 1

' Start at the first record
rstActiveUsers.MoveFirst

' Check each record for the SessionID
Do While Not rstActiveUsers.EOF
' Do conversion to Long to be sure we're
' comparing the same data type.
If CLng(rstActiveUsers.Fields("id").Value) = _
CLng(Session.SessionID) Then
rstActiveUsers.Delete adAffectCurrent
End If

rstActiveUsers.MoveNext
Loop

rstActiveUsers.Update
End Sub

Sub Application_OnEnd()
' Not like it really matters, but for the sake of
' good coding practice I close the recordset when
' our application is shutting down.
rstActiveUsers.Close
End Sub
</script>


Kamran A
14/m/mn
Minneapolis, MN
Web Dev/Flash Dev

SubKamran
Junior Member

101 Posts

Posted - 13 May 2002 :  23:21:06  Show Profile  Visit SubKamran's Homepage  Send SubKamran an AOL message  Send SubKamran a Yahoo! Message
nevermind! just had to wait longer...works now...

Kamran A
14/m/mn
Minneapolis, MN
Web Dev/Flash Dev
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 1.14 seconds. Powered By: Snitz Forums 2000 Version 3.4.07