World's simplest web page counter

Are you tired of complicated counter programs, with indecipherable code and pages of configuration?

I was! Even counters which claimed to be simple had such complicated configurations that I figured I could write the code from scratch in less time it would take to configure someone else's.

It turns out I was right - with not much effort I have simple text-based counters on all of my pages. The code can keep track of the total number of hits, and also the number of hits over some history period (which defaults to one month). The best part -- the code requires NO configuration, ZERO! Just compile and use:

  • Make sure your server supports SSIs (server side includes)
  • Download counter code PDF and if you want, a short script to compile various versions txt file.
  • Compile the counter.c code. The script produces five programs:
    1. counter - Increment the counter and print a full message
      (this is really the only program you need)
    2. counter_t - Increment the counter and print the total counter number
    3. counter_h - Increment the counter and print the history counter number
    4. counter_t_nu - No update of counter, print only the total counter number
    5. counter_h_nu - No update of counter, print only the history counter number
  • Put the compiled code in your cgi-bin directory.
  • Insert links in your web pages. To use the basic counter routine, as I do on the bottom of this page, just insert

    <!--#exec cgi="/cgi-bin/counter"-->
    If you want to use the counter values in more interesting ways (eg, showing up at the top AND bottom of a page, in which case you have to ensure that you don't double-count), then you can use the counter_* routines. For example

    This page has been accessed a total of <!--#exec cgi="/cgi-bin/counter_t"--> times, with <!--#exec cgi="/cgi-bin/counter_h_nu"--> hits in the past month
    The first #exec increments the counter and prints a total; the second leaves the counters unchanged and prints the hits over the history period.

  • Optional -- preset count values based on past statistics etc. You can run the counter program directly, as

    counter filename totalhits hitsinhistory
    in which case an entry for filename is created (if not yet present) and set to the specified values. A formatted list of all counter values can be found by running

    counter -