SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Daily Counter

  1. #1
    SitePoint Enthusiast montroze's Avatar
    Join Date
    Mar 2002
    0 Post(s)
    0 Thread(s)

    Question Daily Counter

    Anyone use a daily counter that will reset at midnight, just to show the days hits? Didn't like the one at 'okcounter'

  2. #2
    Show me the money lennymos123's Avatar
    Join Date
    Jan 2002
    Birmingham, UK
    0 Post(s)
    0 Thread(s)
    you can try this in ASP

    There are many ways to track usage of a website. The simplest way is with a hit counter, which will give you a raw count, but will not tell you how many people are visiting on any giving day. Utilizing the current date function a text document will be created utilizing the date as part of its naming convention in the same directory (providing that directory has user write access, you may need to place the documents in your cgi-bin depending on your provider) as the page we want the counter to appear on. The .txt file is first read to gain the value of the last hit count, one is added to that number, written to the .txt document, closed and the counter value is written as text to the page. If there is no text document (counter) for the current date one is automatically created. Refresh the content of the output page for a more complete illustration of the working counter.

    <title>(Daily Hit Counter)</title>
    <body bgcolor="#FFFFFF">

    on error resume next

    ' Create a server object
    set fso = createobject("scripting.filesystemobject")

    ' Target the text file to be read.
    ' The text file is continually updated with the current date from the server
    set act = fso.opentextfile(server.mappath("daily_count-"& month(date()) & day(date()) & year(date())&".txt"))

    ' Read the value contained in the current day hit counter
    ' If there is no file for the current day the on error resume next command above
    ' will force the program to the next line
    counter = clng(act.readline)

    ' Add one to the counter. If there was no value the counter will be set to a value of one
    counter = counter + 1

    ' Close the text object.

    ' Create a new text file on the server with the current date as part of the name
    Set act = fso.createtextfile(server.mappath("daily_count-"& month(date()) & day(date()) & year(date())&".txt"), true)

    ' Write the counter value to the text object

    ' Close the text object

    'Write out the date and total hits for the current day
    <%= counter %> Total Hits for <%= date() %>

    Palo Webservices

    No one can make you feel inferior without your consent. Eleanor Roosevelt


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts