zoukankan      html  css  js  c++  java
  • 统计在线人数的基本用法

    [inc.asp:]

    Dim Conn,ConnStr,Uip
    Const DataURL = "data/data.Mdb";
    Conn=Server.CreateObject("ADODB.Connection");
    ConnStr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Server.MapPath(DataURL);
    Conn.Open ConnStr
    Uip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    IF Uip = "" Then Uip = Request.ServerVariables("REMOTE_ADDR")

    连接数据库

    [Online.asp]
    每个页面插入以下代码
    <!--#i nclude file="Inc.asp"-->
    IF Conn.ExeCute("Select * From[Online] where [IP]='"&Uip&"'").Eof Then
       Conn.ExeCute("InSert Into[Online]([IP],[Time])values('"&Uip&"','"&Now()&"')")
    Else
       Conn.ExeCute("Update [Online] Set [Time]='"&Now()&"' where [IP]='"&Uip&"'")
    End IF
       Conn.ExeCute("Delete From[Online] where DateDiff('s',[Time],Now())>=1200") '这句删除超过1200秒没有活动的记录 可根据需要修改
    Dim OnlineNumber
    OnlineNumber = Conn.ExeCute("Select Count(IP) From[Online]")(0)
    Conn.Close
    Set Conn = Nothing '关闭连接 释放资源

    [数据库]
    Online表:
    IP 文本字段 [主键]
    Time 时间格式

    在需要统计的地方插入<%=OnlineNumber%>

    ///////////////////////////

    最基本的 可根据需要扩展
  • 相关阅读:
    简单的多重背包
    完美子图
    活动投票
    人品问题
    售票系统
    最短路径
    优美值
    前端-常用函数记录-持续更新
    前端-单点登录中cookie中domain的思考
    大白话说GIT常用操作,常用指令git操作大全
  • 原文地址:https://www.cnblogs.com/studio313/p/350894.html
Copyright © 2011-2022 走看看