当前位置: 首页 > 图文教程 > 网络编程 > ASP > 如何限制同一用户名同时登陆

ASP
ASP编程中15个非常有用的例子 (二)
ASP与JSP的比较(一)
ASP与JSP的比较(二)
ASP中五种连接数据库的方法
从ASP调用SQL中的图像
用排序串字段实现树状结构(例程:连接字串)
用排序串字段实现树状结构(例程:删除贴子)
用排序串字段实现树状结构(例程:回复表单)
用排序串字段实现树状结构(例程:显示贴子内容)
用排序串字段实现树状结构(例程:显示树)
用排序串字段实现树状结构(存储过程)
用排序串字段实现树状结构(库结构)
用排序串字段实现树状结构(原理)
remote script文档(转载自微软)(一)
remote script文档(转载自微软)(二)
remote script文档(转载自微软)(三)
remote script文档(转载自微软)(四)
remote script文档(转载自微软)(五)
remote script文档(转载自微软)(六)
remote script文档(转载自微软)(七)

ASP 中的 如何限制同一用户名同时登陆


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 105 ::
收藏到网摘: n/a

这个问题我的办法是,用户有个活跃时间间隔问题。超过这个活跃时间间隔的则可以认为是离线,后者可以登陆 ,如果无后者登陆,但并不是说前者就需要重新登陆了。因为他的session还在的。只能是这个时间设置的越小越精确,也是不能做到绝对的。
代码贴出来给楼主参考下。
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 "logined"	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","该帐户已在其他地方登陆,网站设置1个ID只能有1个登陆\n你可以稍候尝试登陆。"	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") &"")) '删除x秒没有活动的访客	End If	If PrvDbState = True Then DbClose()
End Function