Making a counter for a web page

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I need a counter. Nothing fancy. My web host, Ipower, does not provide
any for folks who create web pages with html instead of their tools. I
found this site that looks fine, < .

I have one problem with it. If you go about 1/2 way down the page, you see:
Once you've created the counter script, you now need to cause it to be
run when a page to be counted is viewed. This is done by the following
line inserted in the page:
<!--#include virtual="/cgi-bin/cgiwrap/username/count?filename"-->

Substituting your own username for username above, and also substituting
a filename such as page.hits for filename above. If you're counting
multiple pages, each one should have a unique filename.

For example, the code that counts this page is:
<!--#include virtual="/cgi-bin/cgiwrap/jay/count?countpage"-->

What file name are they talking about? Is this for multiple pages. I'd
only like to put counters on individual pages.


Re: Making a counter for a web page

On Mon, 17 Oct 2011 18:28:37 -0700, W. eWatson wrote:

Quoted text here. Click to load it

Sorry, can't help you sort out what "file name" can or must be. But:

You might want to think about looking into StatCounter,
with their free offerings: .

(Apologies if flogging a service is considered inappropriate here;
I write only as a contented user of their counting/tracking service.)

HTH. Cheers, -- tlvp
Avant de repondre, jeter la poubelle, SVP.

Re: Making a counter for a web page

I may get flamed for answering your question, since it is not an HTML
question, and is therefore off topic here, but here goes...

On 10/17/2011 7:28 PM, W. eWatson wrote:
Quoted text here. Click to load it

The usual best answer to this question is no, you don't. Instead, I will
ask why you think you need it. If you need it to collect statistics that
your host does not provide, then what you really need is to find a new
host. If you need it to provide some sort of "You are visitor number X"
at the bottom of your page, then it may be easier, and just as
effective, to install a random number generator. Better still would be
to leave it off the page entirely.

Quoted text here. Click to load it

Then find a new host. Or not. The fact that they don't provide one may
be wisdom on their part. If you could not install your own, then that
would be reason to find a new host.

You do understand, I hope, that whether you use their tools or not, your
web pages will still be in HTML.

Quoted text here. Click to load it


Quoted text here. Click to load it

Whatever file name you like, as long as each page that contains the
counter has its own corresponding unique file name on the server.

I won't comment on the quality of the counter. I will point you to a
resource that has well-written counters:

BTW, the most appropriate newsgroup for this kind of question was
abandoned by its moderator years ago, and, AFAICT, no longer exists.

Re: Making a counter for a web page

Scott Bryce wrote:

Quoted text here. Click to load it

Heehee. Those were my thoughts exactly. Why do visitors need to know how
many were there ahead of them? --refresh a couple of times

Authors should read their web logs 'n' stats.

"You are visitor number 153 since 1995"  always amused me.

   -This space for rent, but the price is high

Re: Making a counter for a web page

18.10.2011 12:55, Beauregard T. Shagnasty wrote:

Quoted text here. Click to load it

Because then they know what to think of it. One million women can't be
wrong! And on the other hand, some people might be perverse enough to
enjoy the idea of being the first one ever to pen... enter a web page.

Quoted text here. Click to load it

It might be better to make it slightly more serious-looking, e.g. using
a real-time clock with some randomized variation, so that the results
shown are consistent (even when tested on different computers on
different days). They still don't have anything to do with actually
counting visitors, of course.

The idea can however be combined with that of a usual counter. Just make
sure that there is a sufficient number of simulated "visits" in addition
to real visits. If you still have too much spare time, you could make
the pattern of simulated visits resemble the real behavioral patterns
(like few visits when it's midnight for the primary audience, etc.).

Yucca, /

Re: Making a counter for a web page

On Tue, 18 Oct 2011 13:21:00 +0300, "Jukka K. Korpela"

Quoted text here. Click to load it

I'm rather fond of the "Flag Counter" which you can see at the bottom
of my page at /

I'd probably have to migrate to the "pro" version to see what
proportion are female, though. :-)

Steve Swift

Re: Making a counter for a web page

W> I need a counter. Nothing fancy.

/me looks at the calendar

/me shakes head

You're about 15 years out of style, sir.


Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See for Smalltalk discussion

Re: Making a counter for a web page

On 10/17/11 6:28 PM, W. eWatson wrote:
Quoted text here. Click to load it

What you are describing is part of a "server-side include".  This works
on some -- but not all -- Web servers.  It definitely does work on
Apache servers.

The typical way this is done is that you insert code in your HTML file
for a Web page that looks like
    <!--#set var="HTTP_cntrname" value="testit" -->
    <!--#include virtual="/cgi-bin/cntr.ksh" -->
The first line sets the variable HTTP_cntrname to have the value
"testit" (a character string of six characters).  The second line calls
a script file named "cntr.ksh".  You insert this in your HTML file where
you want the counter value to appear.  It will appear in text form as if
it were a preset part of the Web page's content.

The variable in the first line above does require the prefix HTTP_ (or
at least one time, it did); but the name can be anything else that is a
valid UNIX string (that is, not necessarily "cntrname").  That variable
is used in the script cntr.ksh.  With different values in place of
"testit", you can maintain different counters for different Web pages.

The script itself does not have to be named "cntr.ksh".  It does not
even have to be a UNIX script.  I merely prefer Korn UNIX because I did
some extensive work with Korn UNIX some 18 years ago and can write
scripts in that language without having to refer constantly to a
reference manual.

The script requires three print statements, printing the following:
    'Content-type: text/html'
where the 2nd print statement merely outputs an empty (null) string and
"counter" is the computed counter value.  NO, the literal string
"counter" is NOT printed; some counter value computed by the script is
printed.  The script is installed as executable in your address space on
the Web server; for an Apache server, that would be in the cgi-bin
subdirectory.  You would have to ask your Web hosting service what the
root is for your account.  In my case, my root is </rossde>; and my Web
home is </rossde/>.  Thus my counter is in

Finally, any HTML file containing an executable server-side include must
be marked as executable.

Then there is the consideration of how do you construct a counter
script.  That I will leave to you, but I suggest you first read my
< .  Pay special
attention to the white box on the right regarding what you are actually


David E. Ross

Concerned about someone (e.g., the government)
snooping into your E-mail?  Use PGP.
See my <

Re: Making a counter for a web page

On Mon, 17 Oct 2011 18:28:37 -0700, W. eWatson wrote:

Quoted text here. Click to load it

I run a little PHP counter program on my web server. If you need
only one counter for just one page, you can use mine. Do you
want that? I cannot give any long-term guarantee, but my
counters have been running for more than 10 years without any

If your web server can do PHP, you can fairly easily put
counters on your own server. I can point you to the free PHP
software, if you want to do that. Or I can give you the one I
use, which is public domain software that I have improved a bit.


Site Timeline