<% 
	dim rsactiveusers,activeuser
	dim membername
	dim memberword
	dim memberclass
	dim stats
	membername=nohack(request.cookies("lgcookie")("username"))
	memberword=nohack(request.cookies("lgcookie")("password"))
	memberclass=nohack(request.cookies("lgcookie")("userclass"))
	stats=nohack(request.cookies("lgcookie")("stats"))
	set rsactiveusers=server.createobject("adodb.recordset")
	if membername="" then
		'if session("huiyuan")="" then
		'activeuser="select * from bbs_online"
		'else
		activeuser="select * from bbs_online where id="&cstr(session.sessionid)
		'end if
		rsactiveusers.open activeuser,conn,1,3
		'如果无cookie也无登陆
		if rsactiveusers.eof and rsactiveusers.bof then
			rsactiveusers.addnew
			rsactiveusers("id")=Session.SessionID
			rsactiveusers("username")="客人"
			rsactiveusers("userclass")="客人"
			rsactiveusers("ip")=Request.ServerVariables("REMOTE_HOST")
			rsactiveusers("startime")=Now()
			rsactiveusers("lastimebk")=Now()
			rsactiveusers("lastime")=DateToStr(Now())
			rsactiveusers("browser")=Request.ServerVariables("HTTP_USER_AGENT")
			rsactiveusers("stats")=stats
			rsactiveusers.update
		'如果无cookie但已经在线
		else
			rsactiveusers("username")="客人"
			rsactiveusers("userclass")="客人"
			rsactiveusers("lastimebk")=Now()
			rsactiveusers("lastime")=DateToStr(Now())
			rsactiveusers("stats")=stats
			rsactiveusers.update
		end if
		rsactiveusers.close
	'如果有cookie
	else
		if Session.SessionID<>"" then
		activeuser="delete from bbs_online where id="&cstr(Session.SessionID)
		Conn.Execute activeuser
		end if
		activeuser="select * from bbs_online where username='"&membername&"'"
		rsactiveusers.open activeuser,conn,1,3
		'如果有cookie但是没活动记录
		if rsactiveusers.eof and rsactiveusers.bof then
			rsactiveusers.addnew
			rsactiveusers("id")=Session.SessionID
			rsactiveusers("username")=membername
			rsactiveusers("userclass")=memberclass
			rsactiveusers("ip")=Request.ServerVariables("REMOTE_HOST")
			rsactiveusers("startime")=Now()
			rsactiveusers("lastimebk")=Now()
			rsactiveusers("lastime")=DateToStr(Now())
			rsactiveusers("browser")=Request.ServerVariables("HTTP_USER_AGENT")
			rsactiveusers("stats")=stats
			rsactiveusers.update
		else
			rsactiveusers("lastimebk")=Now()
			rsactiveusers("lastime")=DateToStr(Now())
			rsactiveusers("stats")=stats
			rsactiveusers.update
		end if
		rsactiveusers.close
		activeuser="select huiyuan,password from huiyuan where huiyuan='"&membername&"' and password='"&memberword&"'"
		rsactiveusers.open activeuser,conn,1,1
		if rsactiveusers.eof and rsactiveusers.bof then
			Errmsg=Errmsg+"<br>"+"<li>一般程序保护错误，您试图进行不合法的操作。<li>您的密码不正确，请<a href=login.asp>重新登陆</a>。"
			Founderr=true
			call error()
			response.end
		else
		session("huiyuan")=membername
		end if
	end if
	'设置用户不活动超时时间--660秒
	'dim strOnlineTimedOut,strOnlineCheckInTime
	strOnlineCheckInTime = DateToStr(Now())
	strOnlineTimedOut = strOnlineCheckInTime - 1200
	activeuser="delete from bbs_online where lastime<'" & strOnlineTimedOut & "'"
	Conn.Execute activeuser
	set rsactiveusers=nothing
%>