Recent Changes - Search:




Summary: A statistic counter - counts page views, users, languages, browsers, operating systems, referers, locations and web bots
Version: 2010-02-08 - v1.9.2
Maintainer: Blues
Discussion: TotalCounter-Talk
Users: +6 -5 (View / Edit)


  • How can I keep track of total and single page views?
  • How can I see users activity?
  • How can I see from which country my wiki's visitors come?
  • How can I see from which sites my visitors come (who is linking my wiki)?
  • How can I see statistics on which browser/operating system my visitors use?
  • How can I see which web bots are indexing my pages?
  • My hosting service doesn't provide the logs, can I still have some site statistics?


Download unofficial version: totalcounter_1_9_2.phpΔ (see changelog, old official version 1.5. is still available: totalcounter.phpΔ ).

I found that migrating from the 1.5 version to 1.8a that I lost all of my prior total counts. I saw no mention nor documentation that the files where the counts are persisted to was renamed. I found that to retain the prior version total counts you can do one of two things:

  1. Rename the old file names to the new names. This seems to be the better option because you do not have to maintain the change for future script versions.
  2. Change the 1.8a script to point to the old version named file.
Here are the file names for the different versions:
  • Version 1.5 :
    • $file = .total.counter
    • $lock = .total.counter.lock
  • Version :1.8a
    • $file = totalcounter.stat
    • $lock = totalcounter.lock

IchBin Profiles May 15, 2007, at 11:48 AM

Hmm; shouldn't the file names still start with a dot (in future versions of TC)? currently, when searching all pages (?action=search&q=/), a non-existent page named 'totalcounter.stat' is displayed because of the lack of the dot. Optionally, the filenames could be set using some configuration variables. MateuszCzaplinski October 02, 2007, at 02:13 PM

It is a simplified statistics counter which counts a variety of informations such as page views, users browsing, languages used, browsers used by visitors, languages, operating systems used by visitors, referers from which the visitors come from, locations from where the visitors come from and web bots that index the pages.

It does not log single visits but just keeps the total count.


WARNING - i've discovered that as the totalcounter.stat file fills up, when it nears around 1MB in size, all of a sudden totalcounter stops working, and you get error msgs on your site. i think a function within it is timing-out or something. in addition, it becomes impossible to edit your totalcounter.stat file at this point b/c it's owned by 'nobody', and so trying to edit it as some other 'user' is impossible, as you don't have the right priviledges; plus, saving a new totalcounter.stat file is not an option unless you know to set $TotalCounterEnableChmods = 0, which when enabled, prevents totalcounter from writing to the totalcounter.stat file you created. kind of lame thing to discover 8 months into a medium-traffic site with hundreds of pages. am in the process of writing lots of Blacklists in order to prevent the cataloging of unnecessary pages, plus plan to write some blacklists to prevent the cataloging of other information that might be clogging the system - then cleaning out line-by-line from the old totalcounter.stat file. also - there seems to be no active maintenance of this recipe at the moment... beware : (

overtones99, 22 April 2009

My TotalCounter just stopped working at 647 KB count file size, too. Totalcounter 1.9.1, PmWiki 2.2.1, WindowsServer 2003, IIS. It had also stopped 4 weeks ago after counting for 4 weeks ... seems to be reproducable. --Henning April 27, 2009, at 06:33 AM

and now, somehow the totalcounter.stat file has overwritten itself several times over, so that all counts have been reset so many times (without my noticing it) that it'd be pointless to retrieve a backed up copy from 6 months ago... : ( my advice: store pageviews on each page instead!! overtones99 December 22, 2009, at 06:07 AM

SteP January 20, 2010, at 10:28 AM: I recall I had similar problems due to a locking issue. I know that version 1.9.1 fixed a locking issue, but I don't know if it's the same thing that I reported in ( The person who wrote the locking code posted a fix on his board, but the link is now dead. I had saved the code, so I upload it as chozo4-fix.phpΔ. I didn't test it; it needs to be studied and integrated in the latest recipe code, but I stopped using TotalCounter since version 1.8a.
I had similar problems with TotalCounter locking up my whole site and difficult recovery. I really like the functionality it provides, but it's not worth the risk unless that problem is reliably reproduced and fixed. I stopped using this recipe around 1.9.2. Peter Bowers March 27, 2012, at 01:47 AM
Here's a "SimpleSimon" fix for the problems described on this page; no new coding, but it may require some doing, anyway.
  • 1. The problem is that new pages are added to the totalcounter.stat file by the script whether or not there is TotalCounter markup ({$PageViews}) on the page. Pages are added to the stat file when visited, even if it's just one webot visit. A few hundred pages will create a stat file that markedly slows down page opening, usually across the whole site, or even the entire server account, in some cases. So, I would suggest putting the config include in a group or page config customization file, and then restricting that to one or just a few pages. The file could be the site's gateway, with your most important keywords. I'm trying it out, now. -June 10, 2013


Download the script from above and place it in your cookbook directory. Then add include_once('cookbook/totalcounter.php'); in your local configuration (local/config.php).


If you personalize $DefaultGroup and $DefaultName they must be set to the desired value before including the TotalCounter script (see notes below).
You may give a value to the following variables before including the script (e.g. $TotalCounterAuthLevel) to configure some aspects of the TotalCounter:
$TotalCounterAction can be used to change the action for the statistics page (default is 'totalcounter').
ex. $TotalCounterAction = 'totalcounter';
$TotalCounterAuthLevel can be used to change the authorization level necessary to see the statistics page (default is 'admin').
ex. $TotalCounterAuthLevel = 'read';
$TotalCounterMaxItems can be used to set the maximum items to be displayed under each section of the statistics page (default is 20).
ex. $TotalCounterMaxItems = 10;
$TotalCounterEnableLookup can be used to enable the DNS lookup to retrieve the user's location in case the server doesn't do it automatically (default is 0, disabled). Please note that DNS lookup may be a time consuming task.
ex. $TotalCounterEnableLookup = 1;
$TotalCounterBlacklist is an array (of arrays) that can be used to blacklist some items from being logged (the default blacklist is empty).
The available arrays are as follows:
$TotalCounterBlacklist['Pages'], $TotalCounterBlacklist['Users'],
$TotalCounterBlacklist['Browsers'], $TotalCounterBlacklist['OSes'],
$TotalCounterBlacklist['Referers'], $TotalCounterBlacklist['Locations'],
$TotalCounterBlacklist['Bots'], $TotalCounterBlacklist['Languages']
Regular expressions can be used for page names, users and referers, ex
$TotalCounterBlacklist['Pages'] = array('Main.HomePage','/^Site\..*/');
$TotalCounterBlacklist['Users'] = array('Admin','Paul','/^Author.*/');
$TotalCounterBlacklist['Referers'] = array('localhost');
$TotalCounterBlacklist['Locations'] = array('localhost');
$TotalCounterBarColor can be used to personalize the color of the bars in the statistics page. It is a string with the CSS syntax for color (default is '#5af').
ex. $TotalCounterBarColor = '#000';
$TotalCounterBarColor = '#3fca3f';
$TotalCounterShowNumbers is used to show or hide the numbers next to the items in the statistics page (default is 1, enabled).

New in 1.8:

$TotalCounterDownloadManager is used to show all the download counts if you have the DownloadManager cookbook recipe installed. This contains the filename of your download manager stats file.
$TotalCounterGeoIP contains the filename for MaxMind's . This provides more accurate information on where visitors are located, and must be placed in the Wiki.d directory.
$TotalCounterEnableGeoIP set this to 1 to enable GEOIP database lookups, and set $TotalCounterEnableLookup to 0 so that the GEOIP is used, otherwise it defaults to normal behavior for trying to identify the country.

New in 1.9:

$TotalCounterEnableChmods (default: 1). Set this to 0 if your server doesn't allow PHP chmod() function to be run.

(Please see here about integrating GoogleCharts
Possibly a future version would integrate the code.) -- Luigi

(Division by zero if there isn't any visit to some page. Tested in version 1.5) Tasos


After the installation the variables {$TotalCount} and {$PageCount} can be used in the markup to display respectively the total pages visited and the current page views ($TotalCount and $PageCount can be used in a skin .tmpl file in PmWiki versions before 2.1).
$PageCount is the same that is used by the SimplePageCounter, so an upgrade to TotalCounter is possible without changing the markup (but will lose old counts). This also means that the two recipes cannot be used together (why to do it anyway?).
A new page variable is available, {$PageViews}, which can be used as a normal page variable. For example {MyPage$PageViews} gives the page views of the page MyPage.
Can also be used in pagelist templates.
A new action can be used to display a statistics summary page, just add ?action=totalcounter to the url to see the statistics.


The following strings are used and can be internationalized (i18n).
  • $[statistics]
  • $[Page views]
  • $[Pages]
  • $[Percent]
  • $[Count]
  • $[Users]
  • $[Browsers]
  • $[Operating systems]
  • $[Referers]
  • $[Locations]
  • $[Web bots]
  • $[today]
  • $[File Downloads]
  • $[LastDay]
  • $[LastWeek]
  • $[LastMonth]
  • $[LastYear]
  • $[LastYears]


A single text file is saved in the wiki.d directory with the name .total.counter in which the informations are stored. Since the directory already has write permissions, no configuration is needed.
A page view is counted only when action=browse.
When $pagename is empty ('') the recipe counts a hit to the default page $DefaultGroup.$DefaultName, so if you want to change them in your local configuration config.php file, they must be set to the desired value before including the totalcounter.php.
For users statistic count to work a user authentication recipe (UserAuth or AuthUser) must be installed.
For languages statistic count to work the MultiLanguage recipe must be installed.
The .total.counter file format is as follows:
  • the semicolon ";" separates elements.
  • the colon ":" separates values inside the same element.
  • "a" character means array, followed by the number of elements in the array and the elements enclosed in "{}" brackets.
  • "s" character means string, followed by the string length and the string enclosed in double quotes "".
  • "i" means integer, followed by a number that is the value.


You can see the recipe live here, on the bottom left corner the page/total views are displayed (add ?action=totalcounter to the url to see the statistics page).
  • This recipe was last tested on PmWiki version: 2.1.beta20
  • This recipe requires at least PmWiki version: 2.0?


  • 0.1 - 23.06.2005
    • First version, counts page views and total views.
  • 0.2 - 20.11.2005
    • Added action=totalcounter which displays a page with statistics summary.
  • 0.3 - 24.11.2005
    • Added logging of users, browsers, operating systems, referers and locations.
  • 0.4 - 28.11.2005
    • Optimization of the detection routines.
    • Improved detection of the user.
    • Added logging of web bots.
  • 0.5 - 02.12.2005
    • Added possibility to blacklist specific items from being logged.
    • Modified regex for better referer and location detection.
    • Added extended description of location in statistic summary.
  • 0.6 - 14.12.2005
    • Added possibility to DNS lookup the location in case the server doesn't do it automatically.
    • Added detection of location when user is sitting behind a proxy server.
    • Added possibility to blacklist with regexes for pages, users and referers.
    • Listed pages now are link to the actual page.
    • Added possibility to assign a password authorization level (edit, admin, etc).
  • 1.0 - 21.12.2005
    • Corrected a bug when the page is the default page.
    • Corrected a bug which assigned a browser when pages were crawled by a web bot.
    • Optimization of array routines.
    • Public release.
  • 1.1 - 03.01.2006
    • Fixed a bug when no bots are present yet.
    • Now users work with both UserAuth and AuthUser.
    • Added recognition for other popular web bots.
    • Added configuration of bars color in the statistics page.
    • Added numbers on items (configurable).
  • 1.1b - 05.01.2006
    • Fixed a bug with empty blacklist array.
    • Fixed an alignment problem in the statistics page.
    • Fixed a problem which treated Group/Page different from Group.Page.
    • Added version display in the statistics page.
  • 1.1c - 17.01.2006
    • Fixed a problem with the markup to work with 2.1.beta20.
  • 1.2 - 24.01.2006
    • Added links to profile pages for the users.
    • Reduced locking loop to 5 seconds.
  • 1.3 - 30.01.2006
    • Suppressed the modification to $pagename, now uses internal variable.
    • Fixed a bug when remote location is in upper case.
    • Changed creation of lock directory to lock file, to prevent problems with some providers.
  • 1.4 - 31.01.2006
    • Optimized the detection of the current page (using ResolvePageName).
    • Added statistic count of languages (when used with the MultiLanguage recipe).
  • 1.4b - 20.02.2006
    • Added blacklist support for languages.
    • Some fixes about arrays.
  • 1.5 - 07.03.2006
    • Added {$PageViews} page variable.
    • Fixed a problem when ResolvePageName function does not exist (earlier versions of PmWiki).
    • Fixed a problem with PHP version <4.3.
  • unofficial 1.6 - 27.03.2006 - totalcounter_1_6.phpΔ
    • Morison: has also added code (using PHP Sessions) to only count visitors' first visit to each page and to only count their browser, Operating System, referer and location once per session.
    • Florian Xaver:
      • Added os: "DOS"
      • Added browser: "Arachne GPL"
      • Added browser: "Blazer"
      • Changed 'palmos' to 'palm'
    • Schlaefer: a daily page counter, a short input field to set the $TotalCounterMaxItems. Changes he mades have a ## comment.
  • unofficial 1.7 - 26.07.2006 - totalcounter_1_7.phpΔ
    • Florian Xaver:
      • Fixed bug on slow servers where sometimes statistic is reseted. (when many people and/or spambots want to access this site)
      • Removed code from Morison. If you need the feature of counting once per session you have to download from link below.
  • unofficial 1.8 - 01.01.2007 - totalcounter_1_8.phpΔ
    • David Carver:
      • Added ($TotalCounterGEOIP) variable.
      • Added ($TotalCounterEnableGEOIP) - Set to 1 to use MaxMind's GEOIP Database for country identification. Make sure to turn off Lookup (set to 0).
      • Added code to get Location by looking up GEOIP from MaxMind's GEOIP Country database. You will need the PHP library to use this. Create a directory called GEOIP in the cookbook directory and place MaxMind's php files there.
      • Added code to hopefully fix resets of the file.
      • Added ignore_user_abort(true) to keep file from reseting.
      • Minor code refactoring to only open the file in write mode when action=browse
      • Added enhanced file locking mechanism to help keep counter file from reseting.
  • unofficial 1.8a - 2007-01-21 - totalcounter_1_8a.phpΔ
    • Florian Xaver (flox January 21, 2007, at 11:57 AM)
      • Improved/Fixed handling of userlanguage plug-in: (uses $userlang2 instead of $userlang)
      • Fixed handling of "File Downloads" (no "." at the filename)
  • unofficial 1.9 - 01.10.2007 - totalcounter_1_9.phpΔ
    • Mateusz Czaplinski
      • Added time statistics (last day, last month,...). Note: recognized bots are not counted (although that can be changed by commenting out line 450 (if (!isset ($tc_bot)) {) and the corresponding closing bracket on line 455)
      • Chmods can be disabled via configuration option (setting $TotalCounterEnableChmods to 0).
  • unofficial 1.9.1 - 22.01.2008 - totalcounter_1_9_1.phpΔ
    • Mateusz Czaplinski
      • A fix which tries to ensure that the site won't get locked up by TC's lockfile.
      • Added $TotalCounterFile & $TotalCounterLockfile configuration variables.
  • unofficial 1.9.2 - 08.02-2010 - totalcounter_1_9_2.phpΔ
    • Peter Bowers
      • Minor upgrade to correctly identify Google Chrome browsers
  • unofficial 1.9.2 - 10.28-2010 - totalcounter_1_9_2_php5.3.3.phpΔ
    • Nigel?
      • Minor upgrade to replace deprecated eregi() function with preg_replace() to make it php5.3.3 compliant

See Also

See the recipe live here, on the bottom left corner the page/total views are displayed (add ?action=totalcounter to the url to see the statistics page). the action=... does not work 04.07.2008 PKHG How did you include the 'total' pagecount on the bottom left (in the PmWiki?) 04.07.2008 PKHG

What does the Count represent in the statistic Users Percent Count? Thanks for this wonderful recipe? Liz K? December 26, 2008, at 02:51 AM


User notes +6 -5: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.

Edit - History - Print - Recent Changes - Search
Page last modified on February 24, 2014, at 11:39 AM