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