⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 time.asp

📁 一个网站聊天室的模型
💻 ASP
字号:
<% 
'定义变量,记录用户是否超时
dim overtime
'如果用户没有被管理员踢出聊天室,就...
if application(session("myname"))<>"***kickout***" then
'创建数据源连接对象
set newconn=server.CreateObject ("ADODB.Connection")
	dbpath=server.mappath("chatroom.mdb")
	newconn.open "driver={Microsoft Access Driver (*.mdb)};dbq="&dbpath
	

'判断是否超过5分钟
if minute(now)- minute(cdate(application("time")))>=5 or ( minute(now)- minute(cdate(application("time")))<0 and (minute(now)+60-minute(cdate(application("time"))))>=5) then
	'相当于if (minute(now)- minute(cdate(application("time")))>=5 )or (( minute(now)- minute(cdate(application("time")))<0 and (minute(now)+60-minute(cdate(application("time"))))>=5)) then
'因为运算符and的优先级高于or

'从在线用户表中查找用户名,最后发言时间和用户所在的房间名
	mysql="select OnLineUserID,LastTalkingTime,RoomName from UserOnLine"
	'创建记录集对象
	set myrecord1=server.CreateObject ("ADODB.Recordset")
	myrecord1.Open mysql,newconn,1,3
	
	do while not myrecord1.EOF 
	'判断用户是否超过5分钟没有发言,如果是就将该用户的记录从在线用户表中删除
	if minute(now)-minute(cdate(myrecord1("LastTalkingTime")))>=5 or (minute(now)-minute(cdate(myrecord1("LastTalkingTime")))<=0 and minute(now)+60-minute(cdate(myrecord1("LastTalkingTime")))>=5) then
		'更新房间信息表,把该房间中的人数减少一个
		mysql1="update RoomInfo set HowManyUsers=HowManyUsers-1 where RoomName='" & myrecord1("RoomName") & "'"		
		newconn.Execute (mysql1)
		if myrecord1("OnLineUserID")=session("myname") then
		'记录用户超时
			overtime=1
		end if
		'清除聊天内容
		application(myrecord1("OnLineUserID"))=""
		'删除超时用户
		'使用Delete方法将myrecord1对象中的当前记录标记为删除,实际的删除将在调用UpdateBatch方法时进行
		myrecord1.Delete
		myrecord1.UpdateBatch		
	end if
'这个end if是与	if minute(now)-minute(cdate(myrecord1("LastTalkingTime")))>=5 or (minute(now)-minute(cdate(myrecord1("LastTalkingTime")))<=0 and minute(now)+60-minute(cdate(myrecord1("LastTalkingTime")))>=5) then
'语句相对应的
	
	'将记录指针移到下一条记录
	myrecord1.MoveNext 
	loop
	'记录当前时间
	application("time")=now
	'关闭记录集对象
	myrecord1.Close 
	set myrecord1=nothing

end if
'这个end if是与	if minute(now)-minute(cdate(myrecord1("LastTalkingTime")))>=5 or (minute(now)-minute(cdate(myrecord1("LastTalkingTime")))<=0 and minute(now)+60-minute(cdate(myrecord1("LastTalkingTime")))>=5) then
'语句相对应的


'如果用户没有超时,就刷新一遍当前页面中显示的各项时间
if overtime<>1 then
'从在线用户表中查找用户的登录时间
newsql="select LoginTime from UserOnLine where OnLineUserID='" & session("myname") & "'"
set newrecord=newconn.Execute (newsql)
'获得时间
if not newrecord.bof then
   hourdiff=(hour(time)-hour(cdate(newrecord(0))))
if hourdiff<0 then

hourdiff=hourdiff+24

end if
'取得分钟数
mindiff=(minute(time)-minute(cdate(newrecord(0))))
'计算出用户聊天时间
VisitTime=hourdiff*60 + mindiff
%>
<html>
<head>
<title>上站时间</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--说明Web页的格式及编码方式。http-equiv="Content-Type"的实际取值由content的值确定。charset=gb2312表示字符集用简体中文。-->
<meta http-equiv="refresh" content="10;url=currentinfo.asp">
<!--实现每隔10秒刷新一次页面,然后转到currentinfo.asp页面,
这就是在main.asp页面聊天时time.asp,currentinfo.asp和help.asp为什么会交替显示的原因-->

</head>
<body bgcolor="#FFFFCC">
<p><font color="#993333"><small><strong>现在时间是:</strong></small></font></p>
<font color="FF6600"><em><strong>
<% ="   " & now %>
</strong></em></font>
<hr>
<p><strong><font color="#993333"><small>你登录的时间为:<br>
  </small></font><br>
  <font color="FF6600"><em>
  <% =newrecord(0) %>
  </em></font></strong><br>
  <font color="#0080FF"><strong><br>
  </strong></font></p>
<hr>
<p><font color="#993333"><strong><small>你共聊了:</small><br>
  </strong></font></p>
<font color="FF6600"><strong><em>
<% =VisitTime & " 分钟!" %>
</em></strong></font> <font color="#993333"><strong><br>
</strong></font>
<%
'如果用户超时,就判断超时的原因
	else'与if not newrecord.bof then语句相对应
	
	'处理用户帐号被封
mysql2="select faultuserid,idifclosed,ipifclosed from fault"
set myrecord2=newconn.Execute (mysql2)
do while not myrecord2.eof
if myrecord2("idifclosed")=true then
'判断当前用户的帐号是否被封
if myrecord2("faultuserid")=session("myname") then
%>
<script language="javascript">
<!--
window.alert ("你的帐号已经被封,自动退出!")
//转到closeid.asp页面
top.location.href ="closeid.asp"
//-->
</script>
<%
response.End()

end if
end if
'处理用户的IP被封
if myrecord2("ipifclosed")=true then
'判断当前用户的IP地址是否被封
if myrecord2("faultuserid")=session("myname") then
%>
<script language="javascript">
<!--
window.alert ("你的IP地址已经被封,自动退出!")
//转到closeip.asp页面
top.location.href ="closeip.asp"
//-->
</script>
<%
response.End()
end if
end if
	myrecord2.MoveNext 
	loop
	'关闭记录集对象
	myrecord2.Close 
	set myrecord2=nothing
%>
<script language="javascript">
<!--
//用户超时
window.alert ("你发呆时间超过5分钟,自动退出!")
//转到index.asp页面
top.location.href ="index.asp"

//-->
</script>
<%
'session对象的Abandon方法用来消除用户的Session对象并释放其所占用的资源
session.Abandon 
	end if'与if not newrecord.bof then语句相对应
	else'与if overtime<>1 then语句相对应
%>
<script language="javascript">
<!--
//用户超时
window.alert ("你发呆时间过超过5分钟,自动退出!")
//转到index.asp页面
top.location.href ="index.asp"

//-->
</script>
<%
'session对象的Abandon方法用来消除用户的Session对象并释放其所占用的资源
session.Abandon 
	end if'与if overtime<>1 then语句相对应
	
	Response.End 
	'关闭数据源连接对象
	newconn.Close 
	set newconn=nothing
	'被管理员踢出了聊天室
else'与if application(session("myname"))<>"***kickout***" then语句相对应
	
%>
<script language="javascript">
<!--
//用户被踢出聊天室
window.alert ("你由于表现不好,被管理员踢出!")
top.location.href ="index.asp"

//-->
</script>
<%
'session对象的Abandon方法用来消除用户的Session对象并释放其所占用的资源
session.Abandon 
end if'与if application(session("myname"))<>"***kickout***" then语句相对应

%>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -