下面,图老师小编带您去了解一下如何限制同一用户名同时登陆,生活就是不断的发现新事物,get新技能~
【 tulaoshi.com - Web开发 】
这个问题我的办法是,用户有个活跃时间间隔问题。超过这个活跃时间间隔的则可以认为是离线,后者可以登陆 ,如果无后者登陆,但并不是说前者就需要重新登陆了。因为他的session还在的。只能是这个时间设置的越小越精确,也是不能做到绝对的。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.AddNewrsPrv("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") = 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.AddNewrsPrv("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","该帐户已在其他地方登陆,网站设置1个ID只能有1个登陆n你可以稍候尝试登陆。"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 datedIff('s',LastActTime,Now())"&Int(Application("CHECKONLINEDIFF") &"")) '删除x秒没有活动的访客End IfIf PrvDbState = True Then DbClose()End Function
来源:http://www.tulaoshi.com/n/20160219/1599832.html
看过《如何限制同一用户名同时登陆》的人还看了以下文章 更多>>