Due to popular request :), here's a quick draft of "How To Put A Counter On Your Page Using The .stats File".

This is accomplished using these simple steps:

  1. Create a web page
  2. Create a skeleton .stats file
  3. Paste the web page into the .stats file
  4. Insert the magic counter command
That's all! It's that simple.

The above points will be explained a bit further, and it is all spiced up with actual example code, too. In fact, the example code in here can tell you that at least 6427 people have visited this page before you. Isn't that great?

In detail, the example puts a counter in the page called "simplecounter.html" that's on my homepage. That is also the document you are reading right now. The counter is the number in the previous alinea.

But first, a few NOTES!

There, now that's cleaned up too, and we can get to work.

1. Create a web page

We won't teach you this in here. We will assume that you already know how to do this, or you might be able to learn how to do it by looking here. Or simply click the Help button on your browser.

You should have an html document now, where you want to insert a counter as plain text (not as .gif pictures, or whatever. Just the digits in ASCII).

In the example, I simply typed in this document (simplecounter.html) in a text editor. On the spot where the actual counter should place a number, I simply inserted a "0" (zero). Anything would do initially, you'll modify it later in step 4 anyway.

2. Create a skeleton .stats file

You need to create a .stats file in your ~/WWW directory. If you already have a .stats file, then simply stick this to the end of the already existing file (you probably knew that already from reading this, didn't you?)

So, when the page you want the counter in is called simplecounter.html, then this is what you put in the .stats file:

<StatFile simplecounter.html>

</StatFile>
That's all! Now don't leave the editor immediately, because you'll need this again in step 3.

3. Paste the web page into the .stats file

Now you need to put the webpage you created in step 1, into this .stats file you're editing, right between the <StatFile> and the </StatFile> lines. So it gets inserted on the blank line.

Exactly how you do this is depending on the editor you're using. You usually put the cursor on the point where you want to insert it (the blank line in this case), and then you type "control-K control-R simplecounter.html" in joe, or ":r simplecounter.html" in vi's command mode, or "C-x i simplecounter.html" in emacs. *

Now we've already completed step 3, only one more step to go. You can still leave the editor open on that .stats file.

4. Insert the magic counter command

Now you need to actually make the counter count, using a special tag. This is where it gets slightly more difficult, but still not much.

First, find the spot where you want the counter to appear (in the .stats file, not in the original file, which in case of the example is simplecounter.html. You shouldn't edit that file anymore).

Now, delete the number you typed there, and replace it with (provided again that your counter page is simplecounter.html)

<Stats TotalHits url=simplecounter.html>
And that's it! Now write out the .stats file, and watch how it counts.

There is a catch, however. (See also the description of the url= parameter in the .stats description document). If you want to put a counter on your homepage (index.html or index.htm), then you should write, on the position where you want to put the counter:

<Stats TotalHits url= >

This has to do with the way the wwwstats program works internally. It is not really a bug, because it is documented here :). You could call it a misfeature, though. It may get fixed one day.

But remember, this only applies if you put the counter in a file called index.html or index.htm. If you put the counter in another file, then it's all plain and simple, and you put the filename behind the url= specification like the simplecounter.html above.

Also, you always specify the filename on the <StatFile ...> line. So if you want to put a counter on your homepage (index.html), your .stats file would look like this:


<StatFile index.html>
... contents of your index.html file goes here ...
Visitor count: <Stats TotalHits url= >
... more from your index.html file ...
</StatFile>

If you want to know more about how this works, and what else you can do with this, you should read the description of .stats files.