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):
- Mandatory statistics code - the one that counts the visitors;
- Optional counter code - it creates a picture displaying site usage data - graphical counter.
The counter appearance can be changed. Different variants of CNStats graphical counter are described in this article.
By default CNStats counter look as follows:
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:
- Hits for the current day, for the previous day, and total number of hits;
- Hosts for the current day, for the previous day, and total number of hosts;
- Visitors for the current day, for the previous day, and total number of visitors;
- Currently on-line.
CNStats can count robots and display relevant numbers:
- Robots for the current day, for the previous day, and total number;
- Robots/users percentage.
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
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:
- hits - hits for the current day
- hosts - hosts for the current day
- users - users for the current day
- t_hits - total number of hits
- t_hosts - total number of hosts
- t_users - total number of users
- u_hits - users hits for the current day (robots excluded)
- u_hosts - users hosts for the current day (robots excluded)
- u_t_hits - total number of users hits (robots excluded)
- u_t_hosts - total number of users hosts (robots excluded)
- u_hits-hits - robots hits for the current day
- u_hosts-hosts - robots hosts for the current day
- u_t_hits-t_hits - total number of robots hits
- u_t_hosts-t_hosts - total number of robots hosts
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
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
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
The counter design can be changed slightly: you can add shadows; make figures more readable by means of indents.
Counter 5 - Combined
This counter is a combination of all the counters available (mentioned above).
Download
| Example | Reference | System Requirements |
|---|---|---|
| Download | GD, PNG support | |
| Download | GD, PNG support | |
| Download | GD 2.0+, PNG support, TrueType support | |
| Download | GD 2.0+, PNG support, TrueType support | |
![]() |
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:
- Explicit - you can notice it with a naked eye;
- Implicit - you can have no idea of the incorrect calculation.
Below is the list of common mistakes, which cause recording of the incorrect statistics or failure to record statistics at all:
Explicit
- The counter code is not installed;
- CNStats is configured incorrectly;
- 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)
- CNStats is in conflict with the current engine (CMS);
- CNStats is in conflict with the installed Apache modules (for example, mod_security).
Implicit
- The counter code is not installed on all the pages of the website;
- Some Browsers block Cookies.