Hit counter on an .html page?

Live forum: http://forum.freeipodguide.com/viewtopic.php?t=60063


18-04-2007 22:26:45

OK, here's the scoop. I'm learning PHP, I've got some pages which are .phpurl==http://=http:///url and I'm successfully accessing my database, blah blah blah. I can envision how to easily add a simple hit counter to any .phpurl==http://=http:///url pages, but I'd like to be able to have one on .htmlurl==http://=http:///url pages (no other reason for them to be .phpurl==http://=http:///url). Is there a way to do this? I don't care if the hits are a .gifurl==http://=http:///url or just text.


18-04-2007 22:45:27

Check this out http//www.statlogger.com/


18-04-2007 23:13:20

Thanks for the link, but I really want to write my own.


19-04-2007 10:18:38

Yes you can add a counter to an HTML page, but it will require backend server site code (which can be PHP).

One approach is to embed a static img tag in your HTML code, with the src attribute pointing to a PHP page somewhere that counts the link and returns an image. So your image tag could look like

[code10e2cf49c46]<img src="http://myserver.com/hitcounter.php">[/code10e2cf49c46]
The hitcounter.php would simply increment the persistent count (database field) then stream the counter image back in the response. Or if you don't want to actually display a counter in the page, it could return nothing or just 1 pixel. Keep in mind that most hit-counters use algorithms to filter out bogus hits, such as page refreshes or multiple hits from the same IP within a given timeframe.

Ultimately code has to run on the server and the hit-count persisted somewhere, but yes that can be triggered from a static HTML page.