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

online.asp文件

以下为引用的内容:
<!--#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()&"人"")"%>

转载于:https://www.cnblogs.com/wzglweb/archive/2009/02/08/1386431.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值