Counter

This example shows how to make a simple page counter. The COUNTER program is capable of keeping counts for many pages in a single file.

The number of times this page has been read is: ? Could not open web file countsummary.html 1 errors encountered. do a refresh and watch the number count.

The actual HTML that generated the previous line looks like this:

        <P>
        The number of times this page has been read is:
        <!-- #exec cmd="g:\dragonnorth\counter.exe -fg:\dragonnorth\htmltricks\count.inc -ncounter" -->
        do a refresh and watch the number count.
        </P>

To use the counter program you must manually create a file that contains the counts. This file must have a total count (the first line in the file below). The named count lines are optional. They will be added as they are requested by -n arguments to the program. The file count.inc is used to count usage for this counter page. The count.inc file looks like:

        153
        $N counter 86
        $N includer 67
The default security settings for the count.inc file usually prevent the Internet Guest Account from writing this file. The permissions must be updated to allow writing.

This counter system depends on Server side inclusion. Server side inclusion is usually available for files of type .SHTML but not files of type .HTML or .HTM. It can be enabled for these other file types. Read this more complete discussion of Server Side Inclusion. Be sure to follow the SHTML Documentation link for a discussion of how to turn on and enable the exec function. On Windows XP and Windows 2003 servers the counter program is an "Unknown CGI Extension". These are normally disabled and a 404 error will occur. They can be enabled from the IIS manager. Open the local server and the Web Service Extensions folder. Then allow 'All CGI Extensions'. This can be a security hole on systems where users can supply executable programs. Look up 'CGI, troubleshooting 404 errors' in the index of the IIS Manager help section.

The COUNTER program contains more complete documentation, use the command COUNTER -h to get the following documentation typed:

COUNTER version 1.3-4
COUNTER updates a file containing page counts and types the page count.

The previous count file is read and the page and total counts are incremented.
The file is written only if the previous file is correctly read.

The count file contains one line with a total and lines of the form:

    $N  

The page name indicated by -nname is matched to a $N line. The count
of that line is incremented along with the total count. The page count is
reported when -nname is supplied. Otherwise the total count is reported.

Usage is COUNTER [-d#] [-ffilename] [-h] [-nname] [-q[-]] [-u[-]]

    -d#		number of digits in output result.
    -ffilename	file to read and then rewrite with updated count.
    -h		emit a list of commands
    -nname		name is the case sensitive name of a page.
    -q[-]		process and/or update files but be quiet.
    -u[-]		update the count file (default is to update).

You may download COUNTER.EXE including the executable and source code from COUNTER.ZIP. If you find the code useful please send beer money to:

mnewman@dragonnorth.com
Michael Newman
401 Sandy Valley Rd.
Westwood, MA 02090

Look at the SHTML documentation for links to Microsoft's documentation and some important notes that add to that documentation.


DragonNorth.com Webmaster: mnewman@dragonnorth.com