您的位置:首页精文荟萃软件资讯 → 控制用户登陆到网站和显示在线用户列表

控制用户登陆到网站和显示在线用户列表

时间:2004/10/7 19:16:00来源:本站整理作者:蓝点我要评论(0)


            
             
              
             
            

               
               

            



            下面是global.asa的内容:

Sub Application_OnStart
' Delete all saved session information, in case of a crash
set objADO = Server.CreateObject("ADODB.Connection")
sDatabasePath = Server.MapPath("/databases")
sConnection
= "filedsn="&sDatabasePath&"\readwrite.dsn;DBQ="&sDatabasePath&"\sessi
ons.mdb;"
objADO.Open(sConnection)

sUpdateCmd = "delete * from session;"
objADO.Execute(sUpdateCmd)
' Close the database down again
objADO.close
set objADO=Nothing

' Now store the DSN connection string away, so we don't have to look
it up again
Application("sessionDSN") = sConnection

End Sub

Sub Session_OnStart

' Write the session information away into the session database
set session_objADO = Server.CreateObject("ADODB.Connection")
session_objADO.Open(Application("sessionDSN"))
session_sUpdateCmd = "insert into session values
("&Session.SessionID&","
session_sUpdateCmd = session_sUpdateCmd & "'"&Request.ServerVariables
("REMOTE_ADDR")& "',"
session_sUpdateCmd = session_sUpdateCmd & "'"&Request.ServerVariables
("HTTP_USER_AGENT")&"');"
session_objADO.Execute(session_sUpdateCmd)
' Close the database down again
session_objADO.close
set session_objADO=Nothing

End Sub

Sub Session_OnEnd

' Delete the session information from the session database
set session_objADO = Server.CreateObject("ADODB.Connection")
session_sConnection = Application("sessionDSN")
session_objADO.Open(session_sConnection)
session_sUpdateCmd = "delete * from session where
SessionID="&Session.SessionID&";"
session_objADO.Execute(session_sUpdateCmd)
' Close the database down again
session_objADO.close
set session_objADO=Nothing

End Sub

下面是实现功能的一个例子:

<% OPTION EXPLICIT

' currentusers.asp V1.0
' Copyright 1998/99 Bann Consultants barryd@bann.co.uk
' Created 03/11/98 Modified 03/11/98
' On-line documentation at http://www.bann.co.uk/asp/
'
' COPYRIGHT NOTICE
' Copyright 1998-1999 Barry Dorrans All Rights Reserved.
'
' CurrentUsers may be used and modified free of charge by anyone so
long
' as this copyright notice and the comments above remain intact. By
using
' this code you agree to indemnify Barry Dorrans from any liability
that
' might arise from its use.
'
' Selling the code for this program without prior written consent is
' expressly forbidden. In other words, please ask first before you
try and
' make money off of my program.
'
' Obtain permission before redistributing this software over the
Internet or
' in any other medium. In all cases copyright and header must remain
intact
%>

Current User report


Current User Report








<%

DIM objADO, sDatabasePath, sConnection, sessionRecords
DIM userCount

userCount = 0

SET objADO = Server.CreateObject("ADODB.Connection")
sDatabasePath = Server.MapPath("/databases")
sConnection
= "filedsn="&sDatabasePath&"\readonly.dsn;DBQ="&sDatabasePath&"\sessio
ns.mdb;"
objADO.Open(sConnection)

SET sessionRecords = objADO.execute("select * from session;")

DO WHILE NOT sessionRecords.EOF
userCount = userCount + 1
%>


<% sessionRecords.MoveNext
LOOP

sessionRecords.Close
objADO.close
SET sessionRecords = Nothing
SET objADO=Nothing

%>


Session变量的有效期默认为20分钟,可以通过下面来改变它的默认有效期:
Session.Timeout=(有效期的分钟数)

相关阅读 Windows错误代码大全 Windows错误代码查询激活windows有什么用Mac QQ和Windows QQ聊天记录怎么合并 Mac QQ和Windows QQ聊天记录Windows 10自动更新怎么关闭 如何关闭Windows 10自动更新windows 10 rs4快速预览版17017下载错误问题Win10秋季创意者更新16291更新了什么 win10 16291更新内容windows10秋季创意者更新时间 windows10秋季创意者更新内容kb3150513补丁更新了什么 Windows 10补丁kb3150513是什么

文章评论
发表评论

热门文章 360快剪辑怎么使用 36金山词霸如何屏幕取词百度收购PPS已敲定!3

最新文章 微信3.6.0测试版更新了微信支付漏洞会造成哪 360快剪辑怎么使用 360快剪辑软件使用方法介酷骑单车是什么 酷骑单车有什么用Apple pay与支付宝有什么区别 Apple pay与贝贝特卖是正品吗 贝贝特卖网可靠吗

人气排行 xp系统停止服务怎么办?xp系统升级win7系统方电脑闹钟怎么设置 win7电脑闹钟怎么设置office2013安装教程图解:手把手教你安装与qq影音闪退怎么办 QQ影音闪退解决方法VeryCD镜像网站逐个数,电驴资料库全集同步推是什么?同步推使用方法介绍QQ2012什么时候出 最新版下载EDiary——一款好用的电子日记本

Remote Host

Browser

<%=sessionRecords("Host")%>

<%=sessionRecords("BrowserType")%>