|
Cookbook /
SimplePageCounterSummary: A simple page counter of visits to each page
Version: 2007-05-19
Prerequisites: pmwiki-2.2.0
Status:
Maintainer:
Categories: Administration
QuestionCan I keep a simple page counter of visits to each page? Answercounter.phpΔ is a very simple page counter. For every page visited, it will increment a counter, sets a global variable
$PageCount which is also available in the markup as {$PageCount}. The counter file (one file for each page is by default saved as $WorkDir/.$FullName.count - we have write access to $WorkDir anyway.DiscussionAs usual, add Be sure to load the counter.php script after setting your default page. --Pm July 12, 2005, at 09:33 AM 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. Of course there are drawbacks - you additionally clutter your 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). See Also
Comments & BugsAddendum: I modified the counter so that it'd put the files into
$WorkDir/.counters (you have to create the directory first; I didn't want to clutter the code with do-once tasks).And this one won't count non-existing files: counter-bhoc-071124.phpΔ --bhoc 24Nov2007 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 Contributors
This page has been visited 16 times. |