📄 global.asa
字号:
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
'Response.Expires=0
'You can add special event handlers in this file that will get run automatically when
'special Active Server Pages events occur. To create these handlers, just create a
'subroutine with a name from the list below that corresponds to the event you want to
'use. For example, to create an event handler for Session_OnStart, you would put the
'following code into this file (without the comments):
'Sub Session_OnStart
'**Put your code here **
'End Sub
'EventName Description
'Session_OnStart Runs the first time a user runs any page in your application
'Session_OnEnd Runs when a user's session times out or quits your application
'Application_OnStart Runs once when the first page of your application is run for the first time by any user
'Application_OnEnd Runs once when the web server shuts down
sub Application_OnStart
'声明filesystemobject对象的变量
dim fsys
'声明存放记数值的文本文件路径的变量
dim counterfilename
'声明文件对象的变量
dim txtf
'创建对象
set fsys=server.CreateObject("scripting.filesystemobject")
'取得存放记数值的文件的绝对路径,这里存放记数值文件名为"counter.txt"
counterfilename=server.MapPath("counter.txt")
'如果文件存放记数值的文件不存在,创建该文件并将记数值设置为1
if not fsys.FileExists(counterfilename) then
set txtf=fsys.CreateTextFile(counterfilename)
txtf.writeline "1"
txtf.close
set txtf=nothing
end if
'打开文件"counter.txt"读取其中的记数值
set txtf=fsys.OpenTextFile(counterfilename,1)
application("visitornum")=txtf.readline
txtf.close
set txtf=nothing
set fsys=nothing
'锁定application对象的属性,只能当前用户修改
application.Lock
'当天访问人数=0
application("todayvisitor")=0
'目前站上人数=0
application("numonline")=0
'消除application对象的属性锁定
application.UnLock
end sub
sub Application_OnEnd
'声明filesystemobject对象的变量
dim fsys
'声明存放记数值的文本文件路径的变量
dim counterfilename
'声明文件对象的变量
dim txtf
'创建对象
set fsys=server.CreateObject("scripting.filesystemobject")
'取得存放记数值的文件的绝对路径,这里存放记数值文件名为"counter.txt"
counterfilename=server.MapPath("counter.txt")
'打开文件"counter.txt"其中的记数值
set txtf=fsys.OpenTextFile(counterfilename,2)
txtf.writeline application("visitornum")
txtf.close
set txtf=nothing
set fsys=nothing
end sub
sub Session_Onend
'存放当前站上人数的application变量-1
application.Lock
application("numonline")=application("numonline")-1
application.UnLock
end sub
sub Session_OnStart
application.Lock
'存放访问人数的application变量+1
application("visitornum")=application("visitornum")+1
'今天访问人数+1
application("todayvisitor")=application("todayvisitor")+1
'当前站上人数+1
application("numonline")=application("numonline")+1
application.UnLock
'将用户session对象的时限设置为10分钟
session.Timeout=10
end sub
</SCRIPT>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -