欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

ASP实例:即时显示当前页面浏览人数

程序员文章站 2023-12-26 00:00:45
online.文件 <%onlinetimeout...

online.文件

<!--#include file="dbconn.asp" -->
<%
onlinetimeout=10       定义在线活动时间的时间间隔
function userip()
    getclientip = request.servervariables("http_x_forwarded_for")             获得用户的虚拟ip地址
    if getclientip = "" or isnull(getclientip) or isempty(getclientip) then
        getclientip = request.servervariables("remote_addr")                   如果未使用代理服务器,就获得来源的ip地址
    end if
    userip = getclientip
end function
sql="select o_id from c_online where o_ip= "&userip()&" "           在中查找所获得 的ip地址的id
set rs=conn.execute(sql)
if rs.eof and rs.bof then
       sql="insert into c_online(o_ip) values( "&userip()&" )"         如果数据库中没有就表明是新ip,那么插入操作
       conn.execute(sql)
else
       sql="update c_online set o_ltime=now() where o_ip= "&userip()&" "        更数据库的当前时间
       conn.execute(sql)
end if
sql="delete from c_online where dateadd(s,"&onlinetimeout*60&",o_ltime) < now()"        定义十分钟刷新
conn.execute(sql)
rs.close
set rs=nothing
function allonline()
       tmprs=conn.execute("select count(o_id) from c_online")
       allonline=tmprs(0)
       set tmprs=nothing
end function
%>
<%response.write "document.write(""在线"&allonline()&"人"")"%>


上一篇:

下一篇: