Using ASP to display the current online user information, not simply show the number of people that kind! [1] Go

Source: Internet
Author: User
Tags session id servervariables root directory
Show | Online original author: Dong Zi

Global.asa put it in your root directory.
<object runat= "Server" scope= "Application"
Id= "Rstactiveusers" progid= "ADODB. Recordset ">
</object>

<script language= "VBScript" runat= "Server" >
' The ' the ' the ' the ' the ' should notice is the top line.
' It creates an application scoped Recordset object
' Named Rstactiveusers ' I ' ll use the 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 the 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 recordsets so ' we can use it.
' That's basically gets everything ready for our
' The ' I user.
Rstactiveusers.open
End Sub

Sub Session_OnStart ()
' Set session timeout to 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 with 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 ' importance, but it keeps
' 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 ' re free
' To the 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 so we ' ve got the information, all of that ' s
' Left are to display it. 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. The 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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.