Unique Hit Counter

Home

Note: The cookie set by this code will expire after 1 day. This means that if the same user comes back on the same day (user's local time) the re-visit will not count as a hit. If the same user comes back the following day (user's local time) the re-visit will count as a new hit. It would be easy to change the cookie expiration in the AddCookie() function if needed.

'**************************************
' Name: Unique Hit Counter
' Description:This code used cookies to 
'     count unique hits.
if the user has the cookie, Then the hit isn't
counted. if they don't, Then the hit is counted,
and they are given a cookie. All you have To Do 
is use an #include file="nameoffile.asp" and the
correct action is preformed. I made this script 
For my host To count unique hits across his 
networked sites. This is also my submission To 
the asp world of PSC all my expreience is In the 
VB world. I hope you guys like it! 
Later
~/Andy
' By: 
'
'This code is copyrighted and has
' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/xq/ASP/txtCode
'     Id.6501/lngWId.4/qx/vb/scripts/ShowCode.
'     htm
'for details.
'**************************************

<% 'ASP by Atwinda Software
Response.Expires = 0
Dim strNetSite
'This is the only place you have to chan
'     ge the name
'and the name of the file.
strNetSite = "sitename"
if CheckCookie(strNetSite) = "False" Then
    Call CountHit
    Call AddCookie
End if
function CheckCookie(strCookieName)
    if Request.Cookies(strCookieName) = "" Then
        CheckCookie = "False"
    Else
        CheckCookie = "True"
    End if
End function
function AddCookie()
    Response.Buffer = True
    Response.Cookies(strNetSite) = strNetSite
    Response.Cookies(strNetSite).Expires = Date() + 1
End function
function CountHit()
    On Error Resume Next
    Dim objCntFSO, objCntFile, intHits
    Set objCntFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objCntFile = objCntFSO.OpenTextFile(Server.MapPath(strNetSite & ".cnt"), 1)
    intHits = objCntFile.ReadLine
    objCntFile.Close
    Set objCntFile = Nothing
    if intHits = "" Then intHits = 0
    intHits = intHits + 1
    Set objCntFile = objCntFSO.CreateTextFile(Server.MapPath(strNetSite & ".cnt"), True)
    objCntFile.Write intHits
    objCntFile.Close
    Set objCntFSO = Nothing
    Set objCntFile = Nothing
End function
%>