The logic behind the include file
The code behind the include file
Set count =
Server.CreateObject(“ADODB.Connection”)
Set count_rs =
Server.CreateObject(“ADODB.RecordSet”)
count.open
“web_odbc” ‘our dsn is called
web_obdc
my_page =UCase( Request.ServerVariables(“Path_info”)) ‘get the page name from server
var
‘convert to upper case for
consistancy
sql = “Select * FROM Hits where page_name = ‘” & my_page
& “‘”
count_rs.Open sql, count, 3, 3, 1
If count_rs.recordcount ‘ none selected first hit on this
page
sql = “INSERT INTO Hits
(“
sql = sql & ” page_name, total_hits,
day_hits, month_hits, hit_date) VALUES “
sql =
sql & “‘” & my_page &”‘, 1, 1, 1, ‘” & Now() &
“‘)”
count.execute(sql) ‘do an insert into the table for this
page
else
t_hits =
CLng(count_rs.fields(“total_hits”))
d_hits =
CLng(count_rs.fields(“day_hits”))
‘ retrieve hits
m_hits =
CLng(count_rs.fields(“month_hits”))
last_dt =
count_rs.fields(“hit_date”)
td_dt =
Now()
if Abs(DateDiff(“d”,
last_dt, td_dt) 0 THEN ‘if the
hit_date doesnt
match
d_hits = 0
‘ todays date, reset day_hits to
0
end if
if Abs(DateDiff(“m”,last_dt, td_dt) 0
then ‘ same for
month
m_hits = 0
end if
t_hits
= t_hits + 1
d_hits = d_hits + 1 ‘
add 1 to all hits
m_hits = m_hits +
1
count_rs.fields(“total_hits”) =
t_hits
count_rs.fields(“day_hits”) =
d_hits ‘ update the recordset
count_rs.fields(“month_hits”) = m_hits
count_rs.fields(“hit_date”) = Now() ‘ update hit_date with todays
date
count_rs.Update ‘store back to DB
end
if
count_rs.Close ‘ clean up
work
count.Close
Set count_rs = nothing
Set count =
nothing
%>
Now we just include this file in any page we want the hits
tracked
Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved
Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.