<p> online.asp文件</p><code><!--#include file="dbconn.asp" --><br /><%<br />onlineTimeout=10 ''定义在线活动时间的时间间隔<br />Function Userip()<br /> GetClientIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR") ''''''''''''''''''''''获得用户的虚拟IP地址<br /> If GetClientIP = "" or isnull(GetClientIP) or isempty(GetClientIP) Then<br /> GetClientIP = Request.ServerVariables("REMOTE_ADDR") ''''''''''如果未使用代理服务器,就获得来源的IP地址<br /> End If<br /> Userip = GetClientIP<br />End Function<br />sql="select o_id from c_online where o_ip='' "&Userip()&" '' " 在数据库中查找所获得 的IP地址的id<br />Set rs=conn.execute(sql)<br />If rs.eof and rs.bof Then<br /> sql="insert into c_online(o_ip) values('' "&Userip()&" '')" 如果数据库中没有就表明是新IP,那么插入操作<br /> conn.execute(sql)<br />Else<br /> sql="update c_online set o_ltime=now() where o_ip='' "&Userip()&" '' " 更数据库的当前时间<br /> conn.execute(sql)<br />End If<br />sql="delete from c_online where dateadd(''s'',"&onlineTimeout*60&",o_ltime) < now()" 定义十分钟刷新<br />conn.execute(sql)<br />rs.close<br />Set rs=nothing<br />Function allonline()<br /> tmprs=conn.execute("Select count(o_id) from c_online")<br /> allonline=tmprs(0)<br /> set tmprs=nothing<br />end Function<br />%><br /><%Response.Write "document.write(""在线"&allonline()&"人"")"%></code>