一、在線人數統計
制作好一個Global.asa文件,並在里面寫好相關代碼。另外制作一個index.asp頁面,在這個頁面上方顯示目前在線人數(5分鍾內不操作頁面算離線)和網頁被訪問的總次數。關閉頁面后清零。
///////////////Global.asa文件:///////////////////////
<script language="VBScript" runat="Server">
Sub Application_onStart
Application("Count")=0
Application("Online")=0
end sub
Sub session_onStart
session.Timeout=5 //這里是設定會話結束時間(5分鍾)
Application.Lock
Application("Count") = Cint(Application("Count")) + 1 //訪問次數加1
Application("Online") = Cint(Application("Online")) + 1 //在線人數加1
Application.UnLock
end sub
Sub session_OnEnd
Application.Lock
Application("Online") = Cint(Application("Online")) - 1 //會話結束時在線人數減1
Application.UnLock
end sub
</script>
//////////////////index.asp文件部分代碼///////////////////
總訪問人數:<%response.Write(application("Count"))%>人
當前在線:<%response.Write(application("Online"))%>人
缺點:總訪問人數不能累加,就沒有意義,需要另外設置一個ACCESS數據庫記錄訪問人數。而這不是global.asa文件所能實現的,必須使用ASP代碼,如下:
二、總訪問量 統計
在index.asp中加入以下代碼:
Set conner = Server.CreateObject("ADODB.Connection")
conner.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath("count.mdb")
conner.execute("update num set together=together+1 where id=3")
set rs=server.createobject("adodb.recordset")
rs.open "select * from num where id=3",conner,1,3
online=rs("online")
together=rs("together")
rs.close
set rs=nothing
conner.close
set conner=nothing
建立一個ACCESS數據庫,字段分別是:id(自動編號) online together,其中online字段記錄在線人數,together字段記錄總訪問人數,並且不斷累加,每訪問一次頁面,together數據就會更新。