Sub Application_OnStart
'置网站计数器初值
Application("activeusers") = 0
Application("maxusers") = 0
Application("timestamp")= 24
'读取网站浏览量初始值
countfile=server.mappath("/webcount.txt")
Set fs=CreateObject("Scripting.FileSystemObject")
Set thisfile=fs.OpenTextFile(countfile,1,false,false)
Application("webvisitors")=thisfile.readline
thisfile.close
set fs=nothing
End Sub
Sub Session_OnStart
Application("activeusers")=Application("activeusers")+1
Application("webvisitors")=Application("webvisitors")+1
if Application("activeusers")>Application("maxusers") then
Application("maxusers")=Application("activeusers")
End if
Session.LCID=2052
Session.timeout=10
Session("sysmess")="欢迎进入佛山市第一人民医院网站 http://www.fshospital.org.cn"
Session("userid")=""
Session("username")=""
Session("netname")=""
Session("userstat")="0"
Session("permission")=""
Set Session("webconn") = Server.CreateObject("ADODB.Connection")
Session("webconn").Open //数据源自己的
Set Session("webrec") = Server.CreateObject("ADODB.Recordset")
If Application("timestamp")<>Hour(Now) then
'写webcount.txt
countfile=server.mappath("/webcount.txt")
Set fs=CreateObject("Scripting.FileSystemObject")
Set thisfile=fs.CreateTextFile(countfile,true,false)
thisfile.WriteLine(Application("webvisitors"))
thisfile.close
set fs=nothing
'写数据库
dim sqlrec,vdate,yesterday,ctot,tcounter,wfield,hnow
ctot=0
If Application("timestamp")>Hour(Now) then
yesterday=year(date-1)&"-"&month(date-1)&"-"&day(date-1)
'昨日汇总
SQLrec = "SELECT * FROM table where 字段='"&yesterday&"'"
Application.Lock
Session("webrec").Open sqlrec,session("webconn"),3,3
If Session("webrec").EOF then
Session("webrec").Addnew
Session("webrec")("vdate") =yesterday
Session("webrec")("weekname") =Mid("日一二三四五六",Weekday(yesterday),1)
Session("webrec")("intnum")=Application("webvisitors")
Session("webrec")("maxonline") =Application("maxusers")
End if
If Session("webrec")("visitnum")=0 then
Session("webrec")("visitnum") =Application("webvisitors")-Session("webrec")("intnum")
Session("webrec")("maxonline") =Application("maxusers")
Session("webrec")("avenumaday")=(Application("webvisitors")-Session("webrec")("intnum"))/24
End if
'先计算0点前点击率
For Tcounter=1 to 23
wfield="time"&CStr(Tcounter)
ctot=ctot+Session("webrec")(wfield)
Next
ctot=Application("webvisitors")- Session("webrec")("intnum")-ctot
Session("webrec").Update
Application.Unlock
Session("webrec").Close
'添加当日新记录
Application.Lock
SQLrec = "SELECT * FROM table where vdate='"&year(date)&"-"&month(date)&"-"&day(date)&"'"
Session("webrec").Open sqlrec,session("webconn"),3,3
If Session("webrec").EOF then
Session("webrec").Addnew
Session("webrec")("Vdate") =date
Session("webrec")("weekname") =Mid("日一二三四五六",Weekday(date),1)
Session("webrec")("intnum")=Application("webvisitors")
'录入昨天最后一小时的点击率
Session("webrec")("time0") =ctot
Session("webrec").Update
End if
Application.Unlock
Session("webrec").Close
'当日最大在线人数清零
Application("maxusers") = Application("activeusers")
End If
'每小时记录一次访问情况
SQLrec = "SELECT * FROM table where vdate='"&year(date)&"-"&month(date)&"-"&day(date)&"'"
Session("webrec").Open sqlrec,session("webconn"),3,3
Application.Lock
if Session("webrec").EOF then
Session("webrec").Addnew
Session("webrec")("Vdate") =date
Session("webrec")("weekname") =Mid("日一二三四五六",Weekday(date),1)
Session("webrec")("intnum")=Application("webvisitors")
'录入昨天最后一小时的点击率
Session("webrec")("time0") =ctot
end if
wfield="time"&CStr(hour(Now))
if hour(Now)>0 and Session("webrec")(wfield)<=0 then
Ctot =0
For Tcounter=1 to (hour(Now))
wfield="time"&CStr(Tcounter)
Ctot=Ctot+Session("webrec")(wfield)
Next
Session("webrec")(wfield)=Application("webvisitors")- Session("webrec")("intnum")-Ctot
end if
Session("webrec").Update
Application.unlock
Session("webrec").Close
'标记重置
Application("timestamp")=Hour(Now)
End if
End sub
Sub Session_OnEnd
Application("activeusers")=Application("activeusers")-1
End sub
Sub Application_OnEnd
'即时记录当前访问人数
countfile=server.mappath("/webcount.txt")
Set fs=CreateObject("Scripting.FileSystemObject")
Set thisfile=fs.CreateTextFile(countfile,true,false)
thisfile.WriteLine(Application("webvisitors"))
thisfile.close
set fs=nothing
End Sub
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from online where ip='"&remoteaddr&"' and name='"&session("name")&"' or sessionid='"&session.sessionid&"' "
rs.Open sql,Conn,1,3
if rs.eof then
rs.addnew
rs("acturl")=""&acturl&""
rs("ip")=remoteaddr
rs("name")=session("name")
rs("sessionid")=session.sessionid
else
rs("acturl")=""&acturl&""
rs("lasttime")=now
rs("ip")=remoteaddr
rs("name")=session("name")
rs("sessionid")=session.sessionid
end if
rs.update
rs.close
conn.execute("delete from [online] where DateDiff('s',lasttime,Now)>1200 ")
onlinemany=conn.execute("Select count(sessionid) from online")(0)
regonline=conn.execute("Select count(sessionid) from online where name<>''")(0)
%>