当前位置: 首页 > 图文教程 > 网络编程 > ASP > “在线访客”的制作方法

ASP
remote script文档(转载自微软)(八)
不能ASP图像组件来生成图像的ASP计数器程序(二)
不能ASP图像组件来生成图像的ASP计数器程序(三)
用ASP发送邮件
用ASP进行网络打印功能
用ASP实现号码转换
如何用ASP创建日志文件
二十八条改善 ASP 性能和外观的技巧(1-7)
二十八条改善 ASP 性能和外观的技巧(8-14)
二十八条改善 ASP 性能和外观的技巧(15-21)
二十八条改善 ASP 性能和外观的技巧(22-28)
asp实现在web中显示电子表格数据(一)显示数据表格的应用
asp实现在web中显示电子表格数据(二)生成HTML表格
asp实现在web中显示电子表格数据(三)创建数据表列表和名字范围
asp实现在web中显示电子表格数据(四)创建文件选择列表
Carello Web 使 ASP 源码暴露 (APP,缺陷)
MS IIS虚拟主机ASP源码泄露 (MS,缺陷)
虚拟web目录容易泄露ASP源代码 (MS,缺陷)
MS IIS server的ASP安全缺陷 (MS,缺陷)
用WinSock设计Chat程序(转)

ASP 中的 “在线访客”的制作方法


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

  作者:旭旭(07idea)
时间:2003-01-30
E-Mail:[email protected]


======制作原理======

方法就是当用户访问网页时将用户的信息添加进数据库里
在添加的同时,检查数据库里是否有该用户的在线记录,如
果有,则更新该记录,如果没有就把他添加进数据库.
并删除在指定时间内没有活动的在线记录.(大概就是这样吧!)

======数据表设计=======

新建一个数据表,名为"Online"
删除自动编号字段
建立以下字段
字段名:ID      类型:数字
字段名:GUESTNAME    类型:文本
字段名:STATS    类型:文本
字段名:VISITIME    类型:日期/时间
字段名:OUTIME    类型:日期/时间


=======================以下部分源码,供参考,如果写得不好,欢迎指正=======================

<%
sub activeonline()

dim ip

'////删除180秒内不活动的在线记录.
sql="Delete FROM online WHERE DATEDIFF('s',outime,now())>180"
Conn.Execute sql

if stats="" then'//如果stats的值为空,则显示为
stats="不知在做什么?"
else
stats=stats
end if

IP=replace(Request.ServerVariables("REMOTE_HOST"),".","")'////获取IP并消去IP中的"."

'////检查Online表中是否已有这个IP的记录

sql="select id from online where id='"&ip&"'"
set rs=conn.execute(sql)

if rs.eof or rs.bof then'////如果没有该IP记录则添加在线记录

sql="insert into online(id,guestname,stats,visitime,outime) values ("&ip&",'游客','"&stats&"',Now(),Now())"

else'////如果Online表中已有该IP记录则更新该记录

sql="update online set outime=Now(),stats='"&stats&"',guestname='游客' where id='"&ip&"'"

end if
conn.execute(sql)

end sub
%>
==========================实例===========================
将以上代码修改并保存为"Online.asp"嵌入在各网页的尾部

<%

dim conn   
dim connstr
on error resume next
connstr="DBQ="+server.mappath("数据库名称.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr 
'保存为conn.asp文件 
%>

<!--#INCLUDE FILE="conn.asp" -->
<%

dim stats

stats="查看在线"

call activeonline()


Set rs = Server.CreateObject("ADODB.Recordset")
sql="SELECT Id,GuestName,Stats,Visitime,Outime FROM Online ORDER BY Visitime Desc"
rs.open sql,conn,1,3

total=rs.RecordCount

%>
<table border="1" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="53">
  <tr>
    <td width="20%" height="16" align="center">昵称</td>
    <td width="20%" height="16" align="center">动作</td>
    <td width="20%" height="16" align="center">来访</td>
    <td width="20%" height="16" align="center">最后活动</td>
  </tr>
<%do while not rs.eof%>
  <tr>
    <td width="20%" height="28" align="center"><%=rs(1)%></td>
    <td width="20%" height="28" align="center"><%=rs(2)%></td>
    <td width="20%" height="28" align="center"><%=rs(3)%></td>
    <td width="20%" height="28" align="center"><%=rs(4)%></td>
  </tr>
<%
rs.movenext
loop
%>
</table>
在线人数:<%=total%>
<%
rs