帝国软件
  设为首页 加入收藏 关于我们
 
解密帝国网站管理系统
栏 目:
 
您的位置:首页 > 技术文档 > ASP编程
用asp显示当前在线用户信息,不是简单只显示人数那种![1]
作者: 发布时间:2005-03-12 来源:
东子 于 00-9-3 上午 02:35:55 发表在:ASP地带

global.asa 放在你的根目录
<object runat="Server" scope="Application"
id="rstActiveUsers" progid="ADODB.Recordset">
</object>

<script language="VBScript" runat="Server">
' The first thing you should notice is the top line.
' It creates an application scoped recordset object
' named rstActiveUsers that I'll use to store all
' our user information.
'
' Note: I've wrapped it for readability

Sub Application_OnStart()
    ' Selected constants from adovbs.inc
    Const adInteger = 3
    Const adVarChar = 200
    Const adDate = 7
    
    ' Here I set up in memory active user recordset
    ' by adding the fields I want to it and defining
    ' their data types.
    rstActiveUsers.Fields.Append "id", adInteger
    rstActiveUsers.Fields.Append "ip", adVarChar, 15
    rstActiveUsers.Fields.Append "browser", adVarChar, 255
    rstActiveUsers.Fields.Append "started", adDate

    ' Next I open our recordset so that we can use it.
    ' That basically gets everything ready for our
    ' first user.
    rstActiveUsers.Open
End Sub

Sub Session_OnStart()
    ' Set session timeout to 20 minutes
    Session.Timeout = 20

    ' Set a session start time.  This is pretty pointless,
    ' but it does ensure that we start a session and
    ' assign the user a session id and it can help
    ' troubleshooting if we ever need it.
    Session("Start") = Now()
    
    ' Move to the end so records are added in order.
    ' Again not of any real importance, but it keeps our
    ' user table nice and orderly.
    If Not rstActiveUsers.EOF Then rstActiveUsers.MoveLast

    ' Add a record and insert users data.  I'm just
    ' storing some basic info, but naturally you're free
    ' to store whatever you want.
    rstActiveUsers.AddNew
    
    rstActiveUsers.Fields("id").Value = _
        Session.SessionID
    
    rstActiveUsers.Fields("ip").Value = _
        Request.ServerVariables("REMOTE_HOST")
    
    rstActiveUsers.Fields("browser").Value = _
        Request.ServerVariables("HTTP_USER_AGENT")
    
    rstActiveUsers.Fields("started").Value = _
        Now()
    
    rstActiveUsers.Update
    
    ' Now that we've got the information, all that's
    ' left is to display it.  See test_page.asp for a
    ' demo.  It includes the pages show_count.asp and
    ' show_users.asp which can also be used
    ' individually if desired.
End Sub

Sub Session_OnEnd()
    ' Selected constants from adovbs.inc
    Const adSearchForward = 1
    Const adBookmarkFirst = 1
    Const adAffectCurrent = 1

    ' Find the appropriate record.  Using session id is the
    ' easiest way since I use this as the primary key.
    ' This line positions us on the appropriate record.
    rstActiveUsers.Find "id = " & Session.SessionID, _
        0, adSearchForward, adBookmarkFirst
    
    ' Now that we're on the record, delete it.
    ' I use the EOF to make sure we've got one.
    If Not rstActiveUsers.EOF Then
        rstActiveUsers.Delete adAffectCurrent
    End If
End Sub
  
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·用asp "Print this Page" 有需要  (2005-03-12)
 ·用ASP开发一个在线考试程序(二)  (2005-03-12)
 ·用ASP开发一个在线考试程序(三)  (2005-03-12)
 ·用ASP开发一个在线考试程序(四)  (2005-03-12)
 ·用ASP建立一个简单的搜索引擎  (2005-03-12)
 ·用ASP开发一个在线考试程序(一)  (2005-03-12)
 ·利用ASP实现三个强大功能(一)   (2005-03-12)
 ·利用ASP实现三个强大功能(二)   (2005-03-12)
 ·利用ASP实现三个强大功能(三)   (2005-03-12)
 ·用ASP实现免费计数器提供-1  (2005-03-12)

   栏目导行
  PHP编程
  ASP编程
  ASP.NET编程
  JAVA编程
   站点最新
·致合作伙伴的欢迎信
·媒体报道
·帝国软件合作伙伴计划协议
·DiscuzX2.5会员整合通行证发布
·帝国CMS 7.0版本功能建议收集
·帝国网站管理系统2012年授权购买说
·PHPWind8.7会员整合通行证发布
·[官方插件]帝国CMS-访问统计插件
·[官方插件]帝国CMS-sitemap插件
·[官方插件]帝国CMS内容页评论AJAX分
   类别最新
·在ASP中使用数据库
·使用ASP脚本技术
·通过启动脚本来感受ASP的力量
·学习使用ASP对象和组件
·解析asp的脚本语言
·初看ASP-针对初学者
·ASP开发10条经验总结
·ASP之对象总结
·ASP与数据库应用(给初学者)
·关于学习ASP和编程的28个观点
 
关于帝国 | 广告服务 | 联系我们 | 程序开发 | 网站地图 | 留言板 帝国网站管理系统