当前位置: 移动技术网 > IT编程>开发语言>.net > “在线访客”的制作方法

“在线访客”的制作方法

2018年10月10日  | 移动技术网IT编程  | 我要评论

杭州丁桥,朵格拉,情侣说

作者:旭旭(07idea)
时间:2003-01-30
e-mail:kgd1999@21cn.com


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

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

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

新建一个数据表,名为"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."嵌入在各网页的尾部

<%

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>

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网