/PHPVisitorsCounter

PHP Visitors Counter

Primary LanguagePHP

PHP Visitors Counter


A simple visitors counter for your website.

To change default session expiration timeout for current visitors, change counter file location,
change default password (read about it below) or change timezone used for calculations, see:

./php/counter-ajax.php

If double click on the counter div, browser will ask a password to proceed.
If password is passed, should appear modal window with the table inside, which contains useful statistics.
Table contents based on JSON file stored on the server.

If this data is not sensitive in your case, feel free to remove password protection.
Quickest and dirtiest way to do this is to replace this:

password = window.prompt('Enter password');

With this:

password = 'abcd';

In ./js/counter-handler.js


PHP 5.1 compatible (pre json_encode and json_decode).

Counter will store JSON file on your host machine, which has following format:

{
  "now": {
    "users": [
      {
        "expires": 1521313987,
        "visitTime": 1521313807,
        "sessionId": "gx0f6ob9p",
        "clientId": "ghjo3b704",
        "clientIp": "192.168.0.4",
        "clientBrowser": "Internet Explorer 11.0",
        "clientOs": "Windows 7; Desktop",
        "lastUrl": "http:\/\/192.168.0.2\/"
      }
    ]
  },
  "daily": {
    "day": 17,
    "users": [
      {
        "visitTime": 1521313789,
        "sessionId": "d00ocqpya",
        "clientId": "q09rpdwt7",
        "clientIp": "192.168.0.3",
        "clientBrowser": "Firefox 55.0",
        "clientOs": "Windows 8.1; Desktop",
        "lastUrl": "http:\/\/192.168.0.2\/?test=12345"
      },
      {
        "visitTime": 1521313807,
        "sessionId": "gx0f6ob9p",
        "clientId": "ghjo3b704",
        "clientIp": "192.168.0.4",
        "clientBrowser": "Internet Explorer 11.0",
        "clientOs": "Windows 7; Desktop",
        "lastUrl": "http:\/\/192.168.2\/"
      }
    ]
  },
  "total": {
    "count": 6
  }
}