日期:2013-05-08  浏览次数:21056 次

用 ASP 编写简单的日流量,最大日流量统计
-----------------------------------------------------------------------------

<%
'#########- 统计今日流量,最大日流量 -##########

Sub My_Today_Counter()

day1 = cstr(date()) '######- 获得当前日期
Day_Counter_File = Server.MapPath("Counter/Day_counter.ini") '######- 指定计数器文件

set fo = Server.CreateObject("scripting.filesystemobject")
set get_old = fo.OpenTextFile( Day_Counter_File,1,false,false) '######- 读取记录文件
day2 = get_old.ReadLine
Today_Counter = get_old.ReadLine
get_old.close

Application("Todays") = Today_Counter

Set out = fo.CreaTetextFile( Day_Counter_File,true,false )

if day1 = day2 then '#######- 写入今日流量
out.WriteLine( day2 )
Today_Counter = Today_Counter + 1
out.writeline( Today_Counter )
out.Close

Else '######- 新的一天,总结最大日流量
Max_Day_Counter_File = server.mappath("counter/Max_Day_Counter.ini")
Set OutMax = fo.OpenTextFile( Max_Day_Counter_File,1,false,false)
day3 = OutMax.Readline
MaxDayCounter = OutMax.ReadLine '######- 读取最大日流量记录
OutMax.Close

Application("MaxDay") = MaxDayCounter '######- 最大日流量

if Today_Counter-MaxDayCounter>0 then '######- 昨日流量大于最大日流量记录
Application("MaxDay") = Today_Counter '######- 最大日流量
Set OutMax = fo.createtextfile(Max_Day_Counter_File,true,false)
OutMax.WriteLine( day2 ) '######- 如果 day2 有最大日流量
OutMax.WriteLine( Today_Counter ) '######- 写入最大日流量记录
OutMax.Close
End If

Out.WriteLine( day1 ) '######- 创建新一天的日流量统计文件
Today_Counter = 1
out.WriteLine( Today_Counter )
out.Close
end if

End Sub
Application.Lock '锁定
My_Today_Counter '调用过程
Application.UnLock '解开锁定

%>


<td align=center CLASS=BIG><a href="JavaScript:alert('从二零零一年五月一日至今,明日网总流量:<% =Application("counter") %> 今日:<%=Application("todays")%> 最忙:<%=Application("MaxDay")%> (人次) ')" onmouseover="window.status='点击查看流量统计信息'; return true;" onmouseout="window.status=''; return true;">流量统计</a>



===========================================================================
保证以上程序正常运行必须先在此文件运行目录 /counter 下建两个文件

(1)Day_counter.ine
文件内容:

01-11-23
1


(2)Max_Day_Counter.ine
文件内容:

01-11-22
1


<!--##########- 01-11-23 是服务器今天日期-->