代码贴出来给楼主参考下。
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