Asp online count statistics

Source: Internet
Author: User

The simplest method is to use the global. asa file to save the global. asa file to the directory of your host.

The code for the global. asa file is as follows:

<Script Language = "VBScript" runat = "Server">
Sub Application_OnStart
Application ("online") = 0
End Sub
Sub Session_OnStart
Application. Lock
Application ("online") = Application ("online") + 1
Application. UnLock
End Sub
Sub Session_OnEnd
Application. Lock
Application ("online") = Application ("online")-1
Application. UnLock
End Sub
Sub Application_OnEnd
End Sub
</Script>

Response. write (application ("online") where you want to display the number of online users,

Method 2:

Write global. asa:
It is often used in chatting rooms. See the following section.

<Script language = "VBScript" RUNAT = "Server">
Sub Application_OnStart
VisitorCountFilename = Server. MapPath ("/ex2") + "\ VisitCount.txt"
Set FileObject = Server. CreateObject ("Scripting. FileSystemObject ")
Set Out = FileObject. OpenTextFile (VisitorCountFilename, 1, FALSE, FALSE)
Application ("visitors") = Out. ReadLine
Application ("VisitorCountFilename") = VisitorCountFilename
End Sub
'================================================ ============================
SUB Application_OnEnd
Set FileOutObject = Server. CreateObject ("Scripting. FileSystemObject ")
Set Out = FileOutObject. CreateTextFile (Application ("VisitorCountFilename"), TRUE, FALSE)
Out. WriteLine (application ("visitors "))
End Sub
'================================================ ========================= Sub Session_OnStart
Session. Timeout = 5
Application ("visitors") = Application ("visitors") + 1
Session ("ID") = Session. SessionID
End Sub
</SCRIPT>
The file system object operations are used above,

Method 3:

The database is used for storage. This method is troublesome and comprehensive. It is done by recording new IP addresses. If a new IP address exists and the database does not exist, add one, if an IP address is not moved within 20 minutes (according to your own situation,

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.