用asp顯示當前線上使用者資訊,不是簡單只顯示人數那種![1](轉)

來源:互聯網
上載者:User
顯示|線上 原作者:東子

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
    


相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。