dcsimg

Page Hit Counter System Page 3


The hit report page is straightforward. We basically loop thru the hits table and display each  pages results and tally the grand total for the 3 categories( daily, monthly and total). Since we dont rotate all totals automatically we must check the hit_date and todays date to verify if the month and day totals need to be reported.

<HTML>
<TITLE>HIT COUNTER</TITLE>
<BODY>
<table border="1" cellpadding="3" cellspacing="0" width="80%" align="center">

<tr>
<td>
<font size="1" face="Arial"><center>PAGE NAME</font>
</td>
<td>
<font size="1" face="Arial"><center>TOTAL HITS</font>
</td>
<td>
<font size="1" face="Arial"><center>TODAY'S HITS</font>
</td>
<td>
<font size="1" face="Arial"><center>THIS MONTHS HITS</font>
</td>
</tr>

<% Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("web_odbc")
Set RS = Conn.Execute("SELECT * FROM hits  ORDER BY total_hits DESC")

total = 0        ' Three variables to running totals
T_MONTH = 0
T_TODAY = 0

Do While NOT RS.EOF %>
<%
td_dt = now()

if datediff("d",RS("last_dt"), td_dt) <> 0 then  'check to see if the hits are todays
    todays_hits = 0   'hits not today so dont include
else
   todays_hits = RS("today")  'they were today so include
end if
if datediff("M",RS("last_dt"), td_dt) <> 0 then ' check to see if the hits are this months
   MONTHS_hits = 0
else
   MONTHS_hits = RS("MONTH")
end if
%>
<tr>
<td width="80%">
<a href="<%= RS("page_name") %>"><%= RS("page_name") %></a></font>
</td>
<td align="right">
<font size="2">
<%= RS("total") %><% total = total + CLng(RS("total")) %>
</td>
<td align="right">
<font size="2">            'print and add to running totals
<b><%= todays_hits %><% T_TODAY = T_TODAY + CLng(TODAYS_HITS) %></b>
</td>
<td align="right">
<font size="2">
<b><%= MONTHS_hits %><% T_MONTH = T_MONTH + CLng(MONTHS_hits) %></b>
</td>
</tr>

<% RS.MoveNext
Loop

RS.Close
Conn.Close

set rs = nothing
set conn = nothing %>


</table><BR><BR><CENTER>

'write out grand totals
<BOLD>TOTAL PAGE HITS: <%=total%><BR>
TOTAL HITS TODAY:<%=T_TODAY%><BR>
TOTAL THIS MONTH:<%=T_MONTH%><BR> <br>


CURRENT ONLINE USERS : <%=APPLICATION("a_online_user")%> <BR>
HIGHEST NUMBER OF SIMULTANEOUS CONNECTIONS: <%=APPLICATION("a_max_connect")%>

This article was originally published on Jan 11, 1999
Page 3 of 4

Thanks for your registration, follow us on our social networks to keep up-to-date