Visit Counter II

Discussion in 'ASP General' started by Paul W Smith, Aug 28, 2008.

  1. Paul W Smith

    Paul W Smith Guest

    The code below works as a page counter for me, counting how many visits my
    web site has per week (Sunday - Saturday). This works fine - it write the
    date and the count to a text file e.g.

    15/8/2008
    1001

    When the new week arrives the old information is just overwritten, however
    what I would like to do is keep the old information but starting the new
    week with two new lines appended to the top of the existing information so
    maintaining the historical data.

    or

    I actually can write the code that appends the two new lines when the new
    week starts. However I do not have sufficient knowledge to be able to write
    the ASP required to either amend the top two lines of the textstream (for
    when the total should be added).

    Any help or references gratefully received.

    PWS

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


    strCountFileName = Server.MapPath(Request.ServerVariables("SCRIPT_NAME") &
    ".cnt")

    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

    Set objCountFile = objFSO.OpenTextFile(strCountFileName, 1, True)

    If Not objCountFile.AtEndOfStream Then
    dtDate = CDate(objCountFile.ReadLine)
    iCount = CLng(objCountFile.ReadLine)
    Else
    dtDate = Date
    iCount = 0
    End If

    objCountFile.Close
    Set objCountFile = Nothing

    If IsEmpty(Session("TotalCount")) Then

    If Weekday(Date(),vbSunday) = 1 And dtDate <> Date then
    iCount = 1
    Else
    iCount = iCount + 1
    End If
    dtDate = Date

    End If

    Session("TotalCount")= iCount

    Set objCountFile = objFSO.CreateTextFile(strCountFileName, True)

    objCountFile.WriteLine dtDate

    objCountFile.WriteLine iCount

    objCountFile.Close
    Set objCountFile = Nothing

    Set objFSO = Nothing

    Response.Write iCount
    Paul W Smith, Aug 28, 2008
    #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. xerj
    Replies:
    4
    Views:
    349
  2. Jonas Auken
    Replies:
    1
    Views:
    1,765
    Steven Cheng[MSFT]
    Oct 12, 2004
  3. The Eeediot
    Replies:
    3
    Views:
    2,225
    =?Utf-8?B?UnVsaW4gSG9uZw==?=
    Dec 22, 2004
  4. George2
    Replies:
    1
    Views:
    792
    Alf P. Steinbach
    Jan 31, 2008
  5. TomCat

    Website visit counter in JavaScript

    TomCat, May 11, 2005, in forum: Javascript
    Replies:
    6
    Views:
    308
    Randy Webb
    May 18, 2005
Loading...

Share This Page