鉴于大家对asp十分关注,我们编辑小组在此为大家搜集整理了“如何限制同一用户名同时登陆”一文,供大家参考学习
这个问题我的办法是,用户有个活跃时间间隔问题。超过这个活跃时间间隔的则可以认为是离线,后者可以登陆 ,如果无后者登陆,但并不是说前者就需要重新登陆了。因为他的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