Can I keep a simple page counter of visits to each page?
counter.phpΔ is a very simple page counter. For every page visited, it will increment a counter, sets a global variable
In your pages, you can embed it into a wikipage as follows:
If you want to use it in a template file, simply use the $PageCount variable.
The counter will update only when action=browse. So only visitors will increment the counters.
If you prefer one Counterfile you may try the modified function (counter-dba.phpΔ) which uses a DBA-Interface. Be aware that the interfaces may vary from provider to provider. DBM usually is not supported anymore by default, but the $db_type may be db3, db4, gdbm or others (see in phpinfo and search for DBA).
Comments & Bugs
Is there a limit for the number of hits that can be counted on a single page? Once I reach 2-million-something hits, the count seems to drop back to a 1-million-something figure randomly. Or could this be the result of the file not being properly written when a server PHP process timeout occurrs? --Henning August 22, 2007, at 08:11 AM
Very late answer, but yes, the script converts counts to Integers, which maxout around 2-million.
Thanks! Maybe there is some way to extend the counting range? Probably not an issue for most pages, it's just my main portal page that is affected. --Henning February 10, 2009, at 08:26 AM ... Hm, never mind, I somehow broke my counter and have now switched over to Cookbook.TotalCounter. --Henning February 20, 2009, at 06:27 AM ... I'm back to SimpleCounter now since TotalCounter has a size limit too. --Henning April 27, 2009, at 09:24 AM
Looking at the bit count, I wonder if the 2-million-count-loss issue is really a problem of integer size - 16-bit would be 32768, and 32-bit would be about 2 billion, not 2 million ... any ideas how to fix the script to work above 2 millions? --Henning April 27, 2009, at 10:43 AM
As the count on one of my pages just dropped back to a sub-1000 number from a 10000-plus number, there might not be a fixed limit at all, but a different kind of (or additional) problem ... --Henning May 06, 2009, at 05:16 AM
The above problem is most likely a race condition updating the counter file, as no locking is done. Here's a version I did that adds file locking, and seems to work for me: (counter-paxed-20091130.phpΔ) paxed November 30, 2009, at 01:40 PM
Paxed, many thanks! Your explanation makes perfect sense to me, so I have just installed your version on my system with the full confidence that it will solve the issue once and for all! :-) --Henning December 03, 2009, at 10:56 AM
Follow-up: SimplePageCounter has in fact been running flawlessly since December 2009, registering millions of hits on tens of thousands of pages. Thanks again! --Henning August 08, 2012, at 09:10 AM
Is there a way to make a page list ordered by the number of visits? If not, does "TotalCounter" does that and are the stats transferable from one system to another? (by Larienna September 3rd, 2012)
This page has been visited 1560 times.