Inclusion This header appears on each page.

Inclusion Home
SHTML documentation

frameworkstart contents
frameworkend contents

These links appear on each page down the left edge of the page giving the site a common look and feel.


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: 780 do a refresh and watch the number count.

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

        The number of times this page has been read is:
        <?php echo exec("/var/www/html/pictures/counter.exe -f/var/www/html/dragonnorth/htmltricks/ -ncounter"); ?>
        do a refresh and watch the number count.

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 is used to count usage for this counter page. The file looks like:

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

This counter system depends on PHP or server side inclusion. PHP is used in this example.

On Windows systems 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:


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.

Filename for -w is countsummary.html if not given.

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

    -d#         number of digits in output result (default 0).
    -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).
    -w[-]               turns output of web page on or off (default off).
    -wfilename       build a web page that displays the current counts.

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:
Michael Newman
16 Nason Hill Laned
Sherborn, MA 01770

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

This footer shows up at the end of each page.
The number of times one of the inclusion pages has been read is: 2370 Webmaster: