how a counter works?

Can you tell me how a counter works (as simple as you can):
1. Is a counter just some script code in the page HTML program?
2. Or, we must use some program in the server?
3. Is the free counter only a link to the site that can analyze my web?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

a hit counter requires a value to be stored on the web server - this value is incremented with each request to the page concerned.

There are two main ways of achieving this - all involve a call to a CGI program residing on the server.

1 - <IMG> tag: graphical counters increment the value and then dynamically stitch together a GIF image which is returned to the browser.

2 - SSI include: the #exec command in a Server Side Include line can instruct the server to execute a counter CGI which will return a text string showing the number of hits

some of the more advanced CGIs can handle multiple pages with their own counts - a parameter in the CGI call specifies the particular page you are counting.  

the way that most free coutners work is with an IMG tag to a CGI on their server - with a parameter identifying your page.  Their counter will then return a dynamically created image that shows the number of hits to your page and your page only.

If you're interested in looking at some CGIs, go to and look at the cgi/counters section


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
learnAuthor Commented:
Hi shivers,

Thank you.

Say, I got a web site based on server1 and a counter based on server2. Do you mean server2 checks my web every minutes to see how many visitors visiting my web and I can go to a page of server2 to get the data?

Can I just put some script code in my page without the help from other server?
for the first part:

no - no checking is done by server2 - but when a user acccesses the page on server1, the browser looks at the HTML code and sees where all the images are located and downloads them all - the counter one will be located on server2, so the browser contacts server2 to obtain that image - this invokes the CGI which increments the counter number and returns an image reflecting the value of that number

for the second part:

only if you use server side scripting that can store information in a database or file on the server (such as PHP).  Javascript/VBscript is client side (executed in the browser) and so cannot be used for a counter
oops, also:

i dont know if any free counter servers offer extra stats on who has visited your site - the usual way to check the number of hits is just to visit your own page and look at the counter number; of course this will also have the effect of incrementing the counter as well
learnAuthor Commented:
To shivers:

Thank you very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.