Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

CurrentVisitors

Summary: Display the number of current visitors
Version:
Prerequisites: PmWiki version: 2.0.; last tested on PmWiki version: 2.1.26.
Status:
Maintainer:
Categories: Layout

Questions answered by this recipe

How can I know how many visitors are currently surfing on my site?

Description

Copy CurrentVisitors.phpΔ to the cookbook directory and add include_once("cookbook/CurrentVisitors.php"); to config.php.

Notes

In your wiki pages, add the markup (:CurrentVisitors:) to display the number of visitors (strictly speaking "different IP addresses") that came to your site during the last MaximumNumberOfSecondsToConsiderAVisitorAsCurrent.

The counter will update only when action=browse.

Release Notes

Version 1.23
Sep 26th 2007 edited by Angelo Beck
Minor Bugfix.

Version 1.22
June 10th 2007 edited by Angelo Beck
Stores the maximum count of visitors in a file.

Added the following variables:

(:MaxCurrentVisitors:) displays the maximum number of visitors online at the same time.
(:MaxCurrentVisitorsTime:) displays the time when the maximum of visitors was reached.

Older Versions

Original Script by Christophe David Attach:CurrentVisitors_V1.11.phpΔ

Comments

I tried installing this in a specific page config file, but for some reason, the markup was not activated. It does work if I put it in my general site config.php. Caveman

Of course there is the problem of multiple users under the one IP address, so this may not work for internal sites. - Kersti

for http://free.fr change line:

      while (($file = readdir($DirectoryHandle)) == true) {
          if (is_dir($file) == false) {
            $FileFullPath = $CurrentVisitorsDirectory . '/' . $file;
            $FileStat = stat($FileFullPath);
            $FileAge = $TimeNow - $FileStat[9];
            if ($FileAge > $MaximumNumberOfSecondsToConsiderAVisitorAsCurrent) {
              unlink($FileFullPath);
            }
            else {
              $NumberOfCurrentVisitors++;
            }
          }
      }
      closedir($DirectoryHandle);

to :

      while (($file = readdir($DirectoryHandle)) == true) {
        if ($file != '.' and $file != '..') {
          if (is_dir($file) == false) {
            $FileFullPath = $CurrentVisitorsDirectory . '/' . $file;
            $FileStat = stat($FileFullPath);
            $FileAge = $TimeNow - $FileStat[9];
            if ($FileAge > $MaximumNumberOfSecondsToConsiderAVisitorAsCurrent) {
              unlink($FileFullPath);
            }
            else {
              $NumberOfCurrentVisitors++;
            }
          }
        }
      }
      closedir($DirectoryHandle);

Forceflow: If you want the script to update on edit and foxpost pages too, just change the line that says if (action='browse')
to
if (action='browse' || action='edit' || action='foxpost')

See Also

Contributors

Christophe David original script
Angelo Beck(approve links) version 1.2

Edit - History - Print - Recent Changes - Search
Page last modified on July 10, 2008, at 07:20 AM