> Main > Products and Services > Purchase > Company
English / Russian

Troubleshooting

Counter Design Modification

Requirements: CNStats 2.7 and later; GD 1.0 and later.

During CNStats installation you are offered two types of a code for allocation at the site ("Configuration - Counter Type" section):

The counter appearance can be changed. Different variants of CNStats graphical counter are described in this article.

By default CNStats counter look as follows:

graphical counter CNStats

There are three figures: the uppermost denotes total pageviews, the middle one - pageviews for the current day, the lowermost - hosts for the current day. Further various means of counter appearance modification and ways of displaying other useful information will be considered.

At the end of the article you will be able to examine all the abovementioned counter types and to download them for usage.


Source Data

CNStats counter can display the following information:

CNStats can count robots and display relevant numbers:

Besides, you can create different graphical counters which will display site usage dynamics.


CNStats Counters Design

By default, the counter displaying script is located in CNStats root directory under the name cnts.php (abbr. Counter-Show). It is advisable to name your counter files likewise, for instance, cnts-big.php, cnts-ttf.php etc.

Let's start with a certain standard template, which is mandatory for each CNStats counter code:

<?
error_reporting(E_ALL & ~E_NOTICE);

// Inserting the configuration file.
include "config.php";

// Creating images from the preset template.
$im=ImageCreateFromPng("button.png");

// Connecting to MySql server.
$CONN=@mysql_connect($STATS_CONF["sqlhost"],
                     $STATS_CONF["sqluser"],
                     $STATS_CONF["sqlpassword"]);
if (mysql_errno()==0) {

    // Selecting database
    @mysql_select_db($STATS_CONF["dbname"]);

    if (mysql_errno()==0) {
        // .. performing all necessary actions 
        // for image creation...       
        }
    }

// Sending HTTP header Content-Type
Header("Content-type: image/png");

// Generating images
ImagePng($im);

// Clearing the memory
ImageDestroy($im);
?>

Further this code will be inserted without comments.


Counter 1 - Standard


counter 1 CNStats

The most significant part of the code is SQL query, which transfers the displayed data from the table:

SELECT t_hits,hits,hosts FROM cns_counter

The following features can also be transferred from CNStats tables without overloading the server:

SELECT hits, hosts, users,
       t_hits, t_hosts, t_users,
       u_hits, u_hosts,
       u_t_hits, u_t_hosts
FROM cns_counter;

Herein:

Note! Robots are considered only by "PHP-Include" and "Combined" counters.

Below is the query received by "currently on-line" users (conventionally):

SELECT count(DISTINCT hid) as online
   FROM cns_log
   WHERE date>NOW() - INTERVAL 3 MINUTE;

Counter 2 - Total Hits, Hits for Current Day, Users for Current Day, and Currently On-line


counter 2 CNStats счетчик CNStats

As you can seen from the counter display, another basic image has been used here to put in "Currently on-line" data (indicated by red colour)

Counter 3 - True-Type Fonts for Counter Generation


counter 3 CNStats

Unfortunately, TrueType fonts are not supported by some servers, therefore, this counter is not included into the distribution kit.

This counter displays hits, hosts, and users for the current day.

Counter 4 - Total Hits, Hits for Current Day, Users for Current Day, Robots Percentage


counter 4 CNStats

The counter design can be changed slightly: you can add shadows; make figures more readable by means of indents.

Counter 5 - Combined


counter 5 CNStats counter 5 CNStats

This counter is a combination of all the counters available (mentioned above).

Download

ExampleReferenceSystem Requirements
counter 1 CNStats Download GD, PNG support
counter 2 CNStats Download GD, PNG support
counter 3 CNStats Download GD 2.0+, PNG support, TrueType support
counter 4 CNStats Download GD 2.0+, PNG support, TrueType support
counter 5 CNStats Download GD 2.0+, PNG support, TrueType support

In case you have any difficulties or any suggestions, please contact us us. We are ready to answer all your questions.


Checking If Counter Was Correctly Installed

In fact, it is not that easy to check whether statistics is recorded correctly or not. The miscalculations can be of two kinds:

Below is the list of common mistakes, which cause recording of the incorrect statistics or failure to record statistics at all:

Explicit

  1. The counter code is not installed;
  2. CNStats is configured incorrectly;
  3. The counter code is installed in the wrong place and, therefore, only PHP-par is functioning, while JavaScript part does not work at all. (For the "combined" counter type)
  4. CNStats is in conflict with the current engine (CMS);
  5. CNStats is in conflict with the installed Apache modules (for example, mod_security).

Implicit

  1. The counter code is not installed on all the pages of the website;
  2. Some Browsers block Cookies.