Jag har en online lista som visar vilka som är inloggade, det underliga är att om man inte loggar ut så finns man kvar på online-listan och sen när man loggar in i igen så blir det en dubblett av en själv. Nån som förstår hur jag menar och hur jag kan åtgärda det?
Jag fattar inte varför den inte vill gå in och ta bort inloggade om man inte loggar ut. Det är nästan som att den inte vill gå in i Session_onend
Så här sin min global.asa ut
<object runat="Server" scope="Application"
id="rstActiveUsers" progid="ADODB.Recordset">
</object>
<script language="VBScript" runat="Server">
' The first thing you should notice is the top line.
' It creates an application scoped recordset object
' named rstActiveUsers that I'll use to store all
' our user information.
'
' Note: I've wrapped it for readability
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", adInteger
rstActiveUsers.Fields.Append "ip", adVarChar, 15
rstActiveUsers.Fields.Append "browser", adVarChar, 255
rstActiveUsers.Fields.Append "started", adDate
rstActiveUsers.Fields.Append "username", adVarChar, 30
rstActiveUsers.Fields.Append "userID", adInteger
' 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 = 20
' 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()
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>
Sen när man loggar in så exekueras detta:
If Not rstActiveUsers.EOF Then rstActiveUsers.MoveLast
rstActiveUsers.AddNew
rstActiveUsers.Fields("id").Value = Session.SessionID
rstActiveUsers.Fields("ip").Value = Request.ServerVariables("REMOTE_HOST")
rstActiveUsers.Fields("browser").Value = Request.ServerVariables("HTTP_USER_AGENT")
rstActiveUsers.Fields("started").Value = Now()
rstActiveUsers.Fields("username").Value = Request.Form("Username")
rstActiveUsers.Fields("userID").Value = session("userID")
rstActiveUsers.Update
------------------
Alltid lär man sig något nytt varje dag...
Jo, det verkar som om session_onend inte är så bra. Du får väl lägga till någon kontroll vid inloggning.
found = false
do While not rstActiveUsers.EOF
If rstActiveUsers.Fields("username").Value _
= Request.Form("Username") then
found = true
exit do
End If
rstActiveUsers.MoveNext
Loop
if not found then
If Not rstActiveUsers.EOF Then rstActiveUsers.MoveLast
rstActiveUsers.AddNew
end if
rstActiveUsers.Fields("id").Value = Session.SessionID
rstActiveUsers.Fields("ip").Value = Request.ServerVariables("REMOTE_HOST")
rstActiveUsers.Fields("browser").Value = Request.ServerVariables("HTTP_USER_AGENT")
rstActiveUsers.Fields("started").Value = Now()
rstActiveUsers.Fields("username").Value = Request.Form("Username")
rstActiveUsers.Fields("userID").Value = session("userID")
rstActiveUsers.Update
red: klippte fel kodsnutt :h
------------------ essentitia preter non sans multiplicandum
[Redigerat av LarsG den 23 okt 2001]
263 ms totalt · 4 externa anrop · v20260731065814-full.1dc6f849