比较完整的一套在线人数统计系统
conn.asp
---------------------------------------------------
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
dim conn,connstr
set conn=server.createobject("adodb.connection")
connstr="provider=Microsoft.JET.OLEDB.4.0;data source="&server.mappath("line.mdb")
conn.open connstr
sub dataclose()
conn.close
set conn=nothing
end sub
%>
---------------------------------------------------------------
set.asp
--------------------------------------------------------------
<!--#include file="conn.asp"-->
<%
dim guestip,rson_top,sql_top,rscon
guestip=request.servervariables("HTTP_guest")
if guestip="" then
guestip=request.servervariables("REMOTE_ADDR")
end if
sql_top="select * from online where guestip=“"&guestip&"“"
set rson_top=server.createobject("adodb.recordset")
rson_top.open sql_top,conn,3,3
if rson_top.eof and rson_top.bof then
rson_top.addnew
rson_top("uid")="游客"
rson_top("levels")="0"
rson_top("activetime")=now()
rson_top("guestip")=guestip
else
rson_top("activetime")=now()
end if
rson_top.update
rson_top.close
set rson_top=nothing
“=========================================
“删除指定时间(默认为5分钟)不活动的用户
“=========================================
dim outtime
outtime=5
dim del_old,del_check,del
dim rs_del
del_check=0
del_old=dateadd("n",-outtime,now())
set rs_del=server.createobject("adodb.recordset")
rs_del.open "select * from activecheck",conn,1,3
if rs_del.eof and rs_del.bof then
del=del_old
else
del=cdate(rs_del("lastchecktime"))
end if
if del<=del_old then
rs_del("lastchecktime")=now()
rs_del.update
rs_del.close
del_check=1
else
rs_del.close
end if
set rs_del=nothing
if del_check=1 then
conn.execute "delete * from online where (activetime< #" & del_old & "#)"
end if
%>
<%“=sql_top%>
-----------------------------------------------------------------------
online.asp
----------------------------------------------------------------------
<!--#include file="set.asp"-->
<head>
<meta http-equiv="Content-Language" content="zh-cn">
</head>
<%
dim rson
set rson=server.createobject("adodb.recordset")
rson.open "select * from online order by levels desc",conn,1,1
dim onlineall
do while not rson.eof
onlineall=onlineall+1
rson.movenext
loop
%>
<table border="1" width="100%" id="table1" height="137">
<tr>
<td height="27">当前在线<%=onlineall%>人</td>
</tr>
<tr>
<td>
<table border="1" width="100%" id="table2" height="26">
<%
dim stmp,ii
rson.movefirst
do while not rson.eof
response.write"<tr align=“center“>"
stmp=0
do while not rson.eof
stmp=stmp+1
if stmp>3 then
response.write"</tr>"
exit do
end if
%>
<td width="99" height="30">
<img border="0" src="online_member.gif" width="16" height="15"><%=rson("guestip")%>
</td>
<%
rson.movenext
loop
loop
for ii= 1 to 3-stmp
response.write"<td width=“99“> </td>"
next
response.write"</tr></table>"
%>
</table>
</td>
</tr>
</table>
<%
rson.close
set rson=nothing
call dataclose()
%>
================================================================================
数据库:line.mdb
表:activecheck
字段:lastchecktime 日期/时间
表:online
字段:uid 文本
levels 数字
activetime 日期/时间
guestip 文本
---------------------------------------------------
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
dim conn,connstr
set conn=server.createobject("adodb.connection")
connstr="provider=Microsoft.JET.OLEDB.4.0;data source="&server.mappath("line.mdb")
conn.open connstr
sub dataclose()
conn.close
set conn=nothing
end sub
%>
---------------------------------------------------------------
set.asp
--------------------------------------------------------------
<!--#include file="conn.asp"-->
<%
dim guestip,rson_top,sql_top,rscon
guestip=request.servervariables("HTTP_guest")
if guestip="" then
guestip=request.servervariables("REMOTE_ADDR")
end if
sql_top="select * from online where guestip=“"&guestip&"“"
set rson_top=server.createobject("adodb.recordset")
rson_top.open sql_top,conn,3,3
if rson_top.eof and rson_top.bof then
rson_top.addnew
rson_top("uid")="游客"
rson_top("levels")="0"
rson_top("activetime")=now()
rson_top("guestip")=guestip
else
rson_top("activetime")=now()
end if
rson_top.update
rson_top.close
set rson_top=nothing
“=========================================
“删除指定时间(默认为5分钟)不活动的用户
“=========================================
dim outtime
outtime=5
dim del_old,del_check,del
dim rs_del
del_check=0
del_old=dateadd("n",-outtime,now())
set rs_del=server.createobject("adodb.recordset")
rs_del.open "select * from activecheck",conn,1,3
if rs_del.eof and rs_del.bof then
del=del_old
else
del=cdate(rs_del("lastchecktime"))
end if
if del<=del_old then
rs_del("lastchecktime")=now()
rs_del.update
rs_del.close
del_check=1
else
rs_del.close
end if
set rs_del=nothing
if del_check=1 then
conn.execute "delete * from online where (activetime< #" & del_old & "#)"
end if
%>
<%“=sql_top%>
-----------------------------------------------------------------------
online.asp
----------------------------------------------------------------------
<!--#include file="set.asp"-->
<head>
<meta http-equiv="Content-Language" content="zh-cn">
</head>
<%
dim rson
set rson=server.createobject("adodb.recordset")
rson.open "select * from online order by levels desc",conn,1,1
dim onlineall
do while not rson.eof
onlineall=onlineall+1
rson.movenext
loop
%>
<table border="1" width="100%" id="table1" height="137">
<tr>
<td height="27">当前在线<%=onlineall%>人</td>
</tr>
<tr>
<td>
<table border="1" width="100%" id="table2" height="26">
<%
dim stmp,ii
rson.movefirst
do while not rson.eof
response.write"<tr align=“center“>"
stmp=0
do while not rson.eof
stmp=stmp+1
if stmp>3 then
response.write"</tr>"
exit do
end if
%>
<td width="99" height="30">
<img border="0" src="online_member.gif" width="16" height="15"><%=rson("guestip")%>
</td>
<%
rson.movenext
loop
loop
for ii= 1 to 3-stmp
response.write"<td width=“99“> </td>"
next
response.write"</tr></table>"
%>
</table>
</td>
</tr>
</table>
<%
rson.close
set rson=nothing
call dataclose()
%>
================================================================================
数据库:line.mdb
表:activecheck
字段:lastchecktime 日期/时间
表:online
字段:uid 文本
levels 数字
activetime 日期/时间
guestip 文本
继续阅读
- 上一篇 >:日记时间:2005-06-24 23:37:00,天气:晴 |
- 下一篇 >:测试