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,