Counter appearance 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 the attendance 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 is able to provide the following information for counter display:
- Hits for the current day, for the previous day and total hits quantity;
- Hosts for the current day, for the previous day and total hosts quantity;
- Visitors for the current day, for the previous day and total visitors quantity;
- Currently on-line.
Since CNStats can count robots, it's also possible to display these data:
- Robots for the current day, for the previous day and total quantity;
- Robots/users percentage.
Besides, you can make various graphical counters displaying attendance dynamics.
CNStats counters display
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 begin 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 - the standard one
The most significant part of the code is SQL query, which fetches the displayed data from the table:
SELECT t_hits,hits,hosts FROM cns_counter
The following features can also be fetched 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 hits
- t_hosts - total hosts
- t_users - total 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 users hits (robots excluded)
- u_t_hosts - total 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 robots hits
- u_t_hosts-t_hosts - total robots hosts
Note! Robots are considered only with "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 the current day, users for the current day and currently on-line
As it can be seen from the counter display, another basic image has been used here to put in "Currently on-line" data (marked by red colour)
Counter 3 - True-Type fonts usage for counter generation
Unfortunately, TrueType fonts are not supported at some servers, therefore this counter is not included into the distribution kit.
There are hits, hosts and users for the current day displayed at this counter (for a change).
Counter 4 - total hits, hits for the current day, users for the current day, robots percentage
The counter appearance will be changed slightly: shadows will be added; figures will be made more readable by means of indents.
Counter 5 - all included
The counter presents itself amount of all the previous.
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 would like to suggest something, please, e-mail us. We are ready to answer all your questions.
|