Today, the editor will share with you the introduction of how to restrict the same username from logging in at the same time. Interested friends will learn about it with the editor!
My solution to this problem is that the user has an active time interval problem. Those who exceed this active time interval can be considered offline, and the latter can log in. If the latter does not log in, it does not mean that the former needs to log in again. Because his session is still there. It can only be that the smaller the time setting, the more accurate it is, and it cannot be absolute.
The code is posted for reference by the author.
Function CheckOnline()DIM IP,rsPrv,Sql,PrvDbStatePrvDbState = FalseIf DBSTATE = False ThenDbOpen()PrvDbState = TrueEnd IfSet rsPrv=Server.CreateObject("ADODB.Recordset")If Session("UserName") = "" thenSql="select * from [Online] where SessionID='"& Session.Sessionid &"'"rsPrv.Open Sql,Conn,1,3If rsPrv.Eof thenrsPrv.AddNewsPrv("SessionID") = Session.SessionIDrsPrv("GroupChargeLv") = -1rsPrv("LastActTime") = Now()rsPrv("UserIP") = GetIPrsPrv("OnLineTime") = 0rsPrv("UserWhere") = Request.ServerVariables("HTTP_REFERER")ElsersPrv("UserWhere") = Request.ServerVariables("HTTP_REFERER")rsPrv("OnLineTime") = Request.ServerVariables("HTTP_REFERER")rsPrv("OnLineTime") = rsPrv("OnLineTime") + DateDiff("n",rsPrv("LastActTime"),Now())rsPrv("LastActTime") = Now()End IfrsPrv.UpdatersPrv.Close()'response.Write "notlogin"Else'response.Write "logined"Sql="select * from [Online] where UserName='"& Session("UserName") &"'"rsPrv.Open sql,Conn,1,3If rsPrv.Eof thenrsPrv.AddNewsPrv("SessionID") = Session.SessionIDrsPrv("UserName") = Session("UserName")rsPrv("GroupChargeLv") = Session("GroupChargeLv")rsPrv("LastActTime") = Now()rsPrv("OnLineTime") = 0rsPrv("UserIP")= GetIPrsPrv("UserWhere") = Request.ServerVariables("HTTP_REFERER")ElseIf rsPrv("SessionID") Session.SessionID And Application("LoginSet")(1) = False ThenInfoTo "LoginOut.asp","This account has been logged in elsewhere, the website has 1 ID and can only have 1 login/n You can try login later. "Response.End()End IfrsPrv("UserWhere") = Request.ServerVariables("HTTP_REFERER")rsPrv("OnLineTime") = rsPrv("OnLineTime") + DateDiff("n",rsPrv("LastActTime"),Now())rsPrv("LastActTime")=Now() End IfrsPrv.UpdatersPrv.Close()End IfSet rsPrv = NothingIf DateDiff("s",Application("OnLineLastDelete"),Now()) > Int(Application("DELETEONLINEDIFF")) ThenApplication.Lock()Application("OnLineLastDelete") = nowApplication.UnLock()Conn.ExeCute("delete from [Online] where dateIff('s',LastActTime,Now())>"&Int(Application("CHECKONLINEDIFF") &"")) 'Delete the guest without activity for x seconds End IfIf PrvDbState = True Then DbClose()End FunctionThe above is an introduction to how to restrict the same username from logging in at the same time. I hope you can like it. For more content, please continue to pay attention to the website of the Wrong New Technology Channel!