My solution to this problem is that the user has an active time interval problem. Those that exceed this active time interval can be considered offline. The latter can be logged in. If the latter is not logged in, it does not mean that the former needs to log in again. Because his session is still there. This time can only be set as small as possible and more accurate, but it cannot be absolute.
The code is posted for the poster’s reference.
Function CheckOnline()
DIM IP,rsPrv,Sql,PrvDbState
PrvDbState = False
If DBSTATE = False Then
DbOpen()
PrvDbState = True
End If
Set rsPrv=Server.CreateObject(ADODB.Recordset)
If Session(UserName) = then
Sql=select * from [Online] where SessionID='& Session.Sessionid &'
rsPrv.Open Sql,Conn,1,3
If rsPrv.Eof then
rsPrv.AddNew
rsPrv(SessionID) = Session.SessionID
rsPrv(GroupChargeLv) = -1
rsPrv(LastActTime) = Now()
rsPrv(UserIP) = GetIP
rsPrv(OnLineTime) = 0
rsPrv(UserWhere) = Request.ServerVariables(HTTP_REFERER)
Else
rsPrv(UserWhere) = Request.ServerVariables(HTTP_REFERER)
rsPrv(OnLineTime) = rsPrv(OnLineTime) + DateDiff(n,rsPrv(LastActTime),Now())
rsPrv(LastActTime) = Now()
End If
rsPrv.Update
rsPrv.Close()
'response.Write notlogin
Else
'response.Write logged in
Sql=select * from [Online] where UserName='& Session(UserName) &'
rsPrv.Open sql,Conn,1,3
If rsPrv.Eof then
rsPrv.AddNew
rsPrv(SessionID) = Session.SessionID
rsPrv(UserName) = Session(UserName)
rsPrv(GroupChargeLv) = Session(GroupChargeLv)
rsPrv(LastActTime) = Now()
rsPrv(OnLineTime) = 0
rsPrv(UserIP)= GetIP
rsPrv(UserWhere) = Request.ServerVariables(HTTP_REFERER)
Else
If rsPrv(SessionID) <> Session.SessionID And Application(LoginSet)(1) = False Then
InfoTo LoginOut.asp, this account has been logged in elsewhere, the website can only have 1 login per ID/nYou can try to log in later.
Response.End()
End If
rsPrv(UserWhere) = Request.ServerVariables(HTTP_REFERER)
rsPrv(OnLineTime) = rsPrv(OnLineTime) + DateDiff(n,rsPrv(LastActTime),Now())
rsPrv(LastActTime)=Now()
End If
rsPrv.Update
rsPrv.Close()
End If
Set rsPrv = Nothing
If DateDiff(s,Application(OnLineLastDelete),Now()) > Int(Application(DELETEONLINEDIFF)) Then
Application.Lock()
Application(OnLineLastDelete) = now
Application.UnLock()
Conn.ExeCute(delete from [Online] where datedIff('s',LastActTime,Now())>& Int(Application(CHECKONLINEDIFF) &)) 'Delete visitors who have been inactive for x seconds
End If
If PrvDbState = True Then DbClose()
End Function