|
|
Free ASP Hit
Counter Code
Here
is an ASP-based hit counter written using VBscript that you
are welcome to use on your own site. The counter requires
an ODBC connection on the server named counter with
a uid 'mycounter' and password 'mypassword'.
Adjust the uid and password to whatever you configure in the
ODBC connection. Also, the IF statement in the script checks
the client IP address and adds the hit to the database only
if it comes from outside your own network. You need to change
the values in the script for your own public IP address and
the private subnet (if your server is on your local network)
according to your own network's values. (Browse
to www.boyce.us
and look in the status bar to find your public IP address.)
Delete the IF and End If statements if you want to record
all hits, regardless of source. Check out www.dynu.com
if you would like to add the capability to perform reverse
lookup to resolve the IP address to a host name. You
can download a copy of the database here.
Enjoy!
-
Jim
|
'
Hit counter by Jim Boyce, www.boyce.us
MM_counter_STRING = "dsn=counter;uid=mycounter;pwd=mypassword;"
Dim
clientIPAddress
Dim clientBrowser
Dim clientReferrer
Dim pageURL
clientIPAddress = Request.ServerVariables ("REMOTE_ADDR")
' Exclude hits from your own network, change IP addresses to
suit your network
If clientIPAddress <> "216.239.31.4" and left(clientIPAddress,7)
<> "192.168" then
clientBrowser = Request.ServerVariables
("HTTP_USER_AGENT")
clientReferrer = Request.ServerVariables
("HTTP_REFERER")
pageUrl = Request.ServerVariables
("HTTP_URL")
set cn = Server.CreateObject("ADODB.Command")
cn.ActiveConnection = MM_counter_STRING
cn.CommandText = "INSERT
INTO Hits (page, clientIPAddress, clientBrowser, clientReferrer)
VALUES ("&"'"&pageURL&"'"&","&"'"&clientIPAddress&"'"&","&"'"&clientBrowser&"'"&","&"'"&clientReferrer&"'"&")"
cn.Execute
cn.ActiveConnection.Close
End If
set cn = nothing |
|
|