Custom Hit Counter

Discussion in 'ASP General' started by Trevor L., Nov 25, 2006.

  1. Trevor L.

    Trevor L. Guest

    I decide to put a custom Hit Counter on my page (below). Then I won't be
    reliant on the standard FrontPage one which uses webbots.

    It is called by
    <b>Hit Counter: </b><!--#include file="_fpclass/hit_count.inc"-->
    The code it includes is below.

    OK, it works - sort of.

    If I go to Guestbook and then return via the Home button, the counter
    increases by 3, not 1.

    I can't see why this is happenning.

    After returning, a refresh increases it by 2, then another refresh increases
    it by 1 ??

    I know that many say "Don't use them - it is a sign of an amateur", but I
    would at least like to get it working even if I later decide not to use it.

    I have thought to make it a conditional include, i.e. if document.referrer
    is blank. Is that possible?

    <%
    'Dimension variables
    Dim fsoObject 'File System Object
    Dim tsObject 'Text Stream Object
    Dim filObject 'File Object
    Dim lngVisitorNumber 'Holds the visitor number
    Dim intWriteDigitLoopCount 'Loop counter to display the graphical hit count
    Dim cntDigit 'Holds the digit displayed in the counter

    'Create a File System Object variable
    Set fsoObject = Server.CreateObject("Scripting.FileSystemObject")

    'Initialise a File Object with the path and name of text file to open
    Set filObject = fsoObject.GetFile(Server.MapPath("_private/index.asp.cnt"))

    'Open the visitor counter text file
    Set tsObject = filObject.OpenAsTextStream

    'Read in the visitor number from the visitor counter file
    lngVisitorNumber = CLng(tsObject.ReadAll)

    'Increment the visitor counter number by 1
    lngVisitorNumber = lngVisitorNumber + 1

    'Create a new visitor counter text file over writing the previous one
    Set tsObject =
    fsoObject.CreateTextFile(Server.MapPath("_private/index.asp.cnt"))

    'Write the new visitor number to the text file
    tsObject.Write CStr(lngVisitorNumber)

    'Reset server objects
    Set fsoObject = Nothing
    Set tsObject = Nothing
    Set filObject = Nothing

    'Display the hit count as text
    ' Response.Write(lngVisitorNumber)

    'Loop to display graphical digits
    For intWriteDigitLoopCount = 1 to Len(lngVisitorNumber)
    ' Display the graphical hit count
    cntDigit = Mid(lngVisitorNumber, intWriteDigitLoopCount, 1)
    Response.Write("<img src=""counter_images/")
    Response.Write(cntDigit & ".gif""")
    Response.Write("alt=""" & cntDigit & """>")
    Next
    %>

    --
    Cheers,
    Trevor L.
    [ Microsoft MVP - FrontPage ]
    MVPS Website: http://trevorl.mvps.org/
    Trevor L., Nov 25, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    1
    Views:
    408
    Lucas Tam
    Aug 9, 2004
  2. =?Utf-8?B?RWR3YXJkSA==?=

    Hit counter on aspx page

    =?Utf-8?B?RWR3YXJkSA==?=, Mar 27, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    494
    =?Utf-8?B?RWR3YXJkSA==?=
    Mar 27, 2005
  3. dee

    best way to do hit counter?

    dee, Jul 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    397
  4. dee

    hit counter

    dee, Aug 23, 2005, in forum: ASP .Net
    Replies:
    10
    Views:
    801
  5. CK
    Replies:
    9
    Views:
    384
    Jerry Rasmussen
    Oct 19, 2006
Loading...

Share This Page