In the web community, everybody and his brother have clamored
about wanting a hit counter in their home page. These are
generally implemented (poorly) with a cgi-bin program that
returns a graphic. It looks ugly and doesn't work for folks who
don't load the images or have text-only browsers. The other less
common method is using a server-side include executable program
which is insecure at best and not very efficient (requires an
extra unix process "fork")
We have a better way. We added a server
side include "counter" function, built in to the
server. Now you can have a page hit counter with none of the
traditional problems. In fact, its so efficient that we can
afford to offer it to all of our web customers.
How to set it up
First, turn your HTML document into a SHTML document.
The first thing you have to do is adjust the filename
extension of your web page so that the server recognizes it as
containing server-side includes. Just change the extension to
.shtml. So, for instance, if your web page was named "index.html"
or "index.htm", your new web page should
be named "index.shtml".
Next, create a file to hold the value of the counter.
The first thing you have to do is create a file to hold the
value of the counter. This is an ASCII text file which contains
one line on which the the counter value is stored. This file must
always have the extension ".cnt". The file
can begin with any name, but we recommend that you use the same
base name as the .shtml file you intend to use it in. So, if your
web page was named, "index.shtml," then
name the counter file, "index.cnt". Put
this file on the server, with one line containing the number you
want the counter to start at.
When you put the counter file on the server, it must have
special "access permissions." It must be set read/write
by user, group, and other so that the HTTP server can read and
update it. You can use the chmod command to do this from your FTP
program or from the Unix shell prompt.
On the CrossLink web server, you should use the countifier program instead. This will
convert all .cnt files in your directory into counter files.
Finally, add the counter to your SHTML document.
Add the counter directive in your web page where you want the
counter to appear. This directive looks like a HTML comment. In
its simplest form, its "<!--#counter
file="filename" -->". Filename should be
the base name of the counter file, without the ".cnt"
extension. So, if your counter file is named
"counter.cnt", the counter directive you would use is
"<!--#counter file="counter" -->".
There you go, you now have a counter in your page. Bring up
Netscape and try it out!
Advanced Options:
You can do quite a bit more with the counter than just add one
to it for each hit. You can keep track of page hits silently,
adjust the appearance of the counter, and even do things like
rotating your home page through several backgrounds. Here is the
list of options you can give the counter directive:
<!--#counter
silent="no" width="0" nocommas="no"
min="0" max="2147000000"
rollover="no" increment="1"
ith="no" gfx="#" file="counter"
include="file%i.html" debug="" -->
Where:
- silent: Whether
or not to show the value of the counter to the person
accessing the page. yes - Don't show the counter
to the page's accesser. no - Show the counter to
the page's accesser (default).
- width: The
minimum width of the displayed counter (padded with 0's
if necessary).
- nocommas:
Whether or not to insert commas into the number for
readability. yes - Don't insert commas. no
- insert commas (default). If width is not 0 then no
commas are inserted regardless of the setting in
nocommas.
- max: The
maximum number to count to. When the counter reaches this
number, its behavior is controlled by rollover. By
default the number is near two billion.
- min: The
minimum number to count down to. When the counter reaches
this number, its behavior is controlled by rollover. By
default the number is zero.
- rollover: When
you hit the maximum or minimum allowed number, what do
you do? yes - Flip to the other endpoint. I.e.
if at max, change to min. If at min, change to max. no
- Stop counting. Do not add or subtract any further from
the counter.
- increment: The
number to add to the counter. Default: 1. You may also
use the keyword "random" which means that the
next value of the counter should be a random number
between min and max.
- ith: Whether or
not to append st, nd, rd, or th as appropriate to the end
of the counter (i.e. 1st, 2nd, 3rd,
4th, and so on.) yes - Add the
extension. no - Don't add the extension
(default).
- gfx: Use
graphics (i.e. GIF files) to display the counter number
instead of using a text counter. Put the html markup to
include the graphics where "#" is the digit to
replace. For example, if your counter were at 1,234 and
you used the following line: <!--#counter
ith="yes" gfx="<IMG
SRC=\"gifs/#.gif\">"
file="counter" --> then it would be
replaced by the html markup: <IMG
SRC="gifs/1.gif"><IMG
SRC="gifs/,.gif"><IMG
SRC="gifs/2.gif"><IMG
SRC="gifs/3.gif"><IMG
SRC="gifs/4.gif">
- file: The name
of the file (minus the .cnt extension) to
store the counter in. (For example, if your filename is
"home.cnt" then you should use
file="home".) Warning: the
"file" directive must come after
everything except include and debug.
- include: The
"base" filename (where %i is the counter) of a
file to include in to the document based on the value of
the counter. (For example, if you want to include
pageX.html where X is the value of the counter, use
include="page%i.html".)
- debug, if it
exists, means print out the internal variables at the
point in the command to assist in figuring out why the
counter isn't working. This is provided for expert
users... If you don't understand what its saying, don't
use it.
Oh yeah. By the way, you are the person to
read this page.
Enjoy!
Suggested Uses:
Basic hit counter
Add this to your web document:
Welcome, you are the <strong><!--#counter
ith="yes" file="counter"
--></strong> person to access this web page.
And create the counter.cnt file. It looks like:
Welcome, you are the 1,234,567th
person to access this web page.
Revision History
vA1.1.1-2
- Added yes/no and 1/0 as valid in addition to true/false
vA1.1.1-1
- Added "gfx" option.
- Upgraded to function with Apache 1.1.1
v1.5.1-1
- Added "random" setting to increment option
- Added "yes/no" options for all tags. Previously
the existance of the tag with nothing in the quotes meant
do the opposite of the default. This action is preserved
for backward compatibility.
- Upgraded to function with NCSA httpd 1.5.1
v1.5a-1
- Added "ith" option.
- Upgraded to function with NCSA httpd 1.5a
CROSSLINK |
CUSTOMER-SERVICE HOME |
SEARCH FAQ |
NETWORK STATUS |
CONTACT TECH-SUPPORT
CrossLink Internet Services - 5537 C Hempstead Way, Springfield, VA 22151
703-642-1120 | 1-888-4-CrossLink | FAX: 703-642-1258
web@crosslink.net
©1999 CrossLink Internet; all services subject to our Acceptable Use Policy