asp统计点击数,服务器重启后会清零。能不能保存以前的统计数?

2025-05-23 08:18:38
推荐回答(2个)
回答1:

你可以参考我的计数器:

<%
Dim Counter
Dim CounterFile

Sub Counter_Add()

On Error Resume Next
Counter = 0
Set CounterFile = Server.CreateObject("Scripting.FilesyStemObject")

Application.Lock

CounterFile.Open("Counter.txt")
Counter = CLng(CounterFile.ReadLine)
Counter = Counter + 1
CounterFile.Create "Counter.txt",True
CounterFile.WriteLine(Counter)
CounterFile.Close

Application.Unlock

Set CounterFile = nothing

End Sub

Sub Counter_Read()

On Error Resume Next
Counter = 0
Set CounterFile = Server.CreateObject("Scripting.FilesyStemObject")
CounterFile.Open("Counter.txt")
Counter = CLng(CounterFile.ReadLine)

Set CounterFile = nothing

End Sub
%>

在计数器累加的地方使用Call Counter_Add(),在读取计数器的地方使用Call Counter_Read(),然后用Response.Write(Counter) 输出。

回答2:

是数据丢失了吧.呵呵.没保存在数据库或文本上