tag
Sub excitingHit(hit)
Dim objMail
Set objMail = Server.CreateObject("CDONTS.NewMail")
With objMail
.from = "your_hit_counter@" & Request.ServerVariables("SERVER_NAME")
.subject = "We've had an exciting moment in hit counts!"
.to = "justin@sunsierra.com"
.body = "We've just reached hit number " & hit & " on the server: " &_
Request.ServerVariables("SERVER_NAME")
.send
End With
Set objMail = Nothing
Response.Write "
" & vbCrLf & "" & vbCrLf
End Sub
' the styles for the counter
Const STYLE = "font-weight:bold;padding-left:1px;padding-top:2px;border:1px solid #D9D9D9;background-color:#000000;font-size:12px;font-family:lucida console, andale mono, courier;color:orange;"
' the special event to moitor for
Const HIT_EVENT = 1000
Dim conn, rs, sql, hit, temp, i
Dim uip, fill, newHit
Response.Write "" & vbCrLf & vbCrLf
' used to determine if the current visit created a new record in the db or not
newHit = False
uip = Request.ServerVariables("REMOTE_ADDR")
' SQL to check if the IP already exists and the time stamp is within the past 20 minutes
sql = "SELECT uip FROM hits WHERE uip = '" & uip & "' AND utime >= #" &_
DateAdd("n", -20, Now()) & "#"
Set conn = openConn(conn)
Set rs = conn.execute(sql)
If rs.eof Then
' new visitor, we'll create a new record
sql = "INSERT INTO hits (uip, ubrows, uref, uquery) VALUES ('" & uip & "', '" &_
Request.ServerVariables("HTTP_USER_AGENT") & "', '" &_
Request.ServerVariables("HTTP_REFERER") & "', '" &
Request.ServerVariables("QUERY_STRING") & "')"
conn.Execute sql
newHit = True
End If
rs.close
' count the total number of hits
sql = "SELECT COUNT(id) AS hits FROM hits"
Set rs = conn.Execute(sql)
hit = 0
If Not(rs.eof) Then hit = CStr(rs("hits"))
closeRS rs
closeConn conn
' check if the current hit count is a *special* event
If (((hit Mod HIT_EVENT) = 0) And (newHit)) Then excitingHit hit
' buffer the hit number with leading zeros
If Len(hit) < 6 Then
fill = 6 - Len(hit)
For i = 1 To fill
hit = "0" & hit
Next
End If
' write out the hit count, in a pretty format
Response.Write "
" & vbCrLf
For i = 1 To Len(hit)
Response.Write "" & vbCrLf
Response.Write Left(hit, 1) & "" & vbCrLf
hit = Mid(hit, 2)
Next
Response.Write "
" & vbCrLf
Response.Write "" & vbCrLf & vbCrLf
%>