輕鬆打造ASP計數器
作者:Eve Cole
更新時間:2009-06-23 16:43:18
以下介紹用資料庫實作簡單組成部分
'下面存為count.asp
<%
設定 conn=Server.CreateObject("ADODB.Connection")
conn.Open "driver={Microsoft Access 驅動程式 (*.mdb)};dbq="& Server.MapPath("count.mdb")
%>
<%錯誤繼續下一個%>
<%sql="更新計數設定 hit=hit+1%><%conn.Execute(sql)%>
<%sql = "從計數中選擇*
設定 rs=conn.execute(sql)
%>
<%
'更新每週每日數據
Lasthit=rs("lasthit")
tdate=年(Now()) & "-" & 月(Now()) & "-" & 日(Now())
如果修剪(lasthit)=修剪(tdate)那麼
sql="更新站點設定 dayhit=dayhit+1 其中 id="&request("id")
conn.執行(sql)
' 響應.寫“成功”
別的
sql="更新站點設定 dayhit=1 其中 id="&request("id")
conn.執行(sql)
' 回應.write“錯誤”
結束如果
sql="更新站點集lasthit='"&tdate&"' where ID="&request("id")
conn.執行(sql)
p_year=CInt(年(Now()))-CInt(年(lasthit))
p_month=CInt(月(Now()))-CInt(月(lasthit))
p_day=CInt(天(Now()))-CInt(天(lasthit))
period_time=((p_year*12+p_month)*30+p_day)
如果 cint(period_time)=< cint(7) 那麼
sql="更新站點設定 weekhit=weekhit+1 其中 id="&request("id")
conn.執行(sql)
別的
sql="更新站點設定 weekhit=1 其中 id="&request("id")
conn.執行(sql)
結束如果
%>
document.write('<tr><td width="100%">今日訪問<%=rs("dayhit")%>次、本週訪問<%=rs("weekhit")%>次、總訪問<%=rs("hit")%>次</td></tr>');
<%rs.關閉
設定 rs=無%>
'用<script language="JavaScript1.1" src="count.asp"></script>在要統計的頁面呼叫即可。
建立資料庫:建一個count的MDB函式庫,再建一個表count,表中欄位為
打數字型
dayhit數字型
weekhit數位型
Lasthit 日期類型