PHP Classes
elePHPant
Icontem

ezcounter: User visit or hit counter without cookies

Recommend this page to a friend!
  Info   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2007-05-03 (9 years ago) RSS 2.0 feedStarStarStar 48%Total: 1,818 This week: 1All time: 2,092 This week: 1,047Up
Version License Categories
counter 1.0Freely DistributableStatistics, User Management
Description Author

This class is meant to count user visit or page hits.

It is text based (no database) and the (text) output digits can be formatted with CSS when a CSS class is defined.

Picture of Peter Klauer
Name: Peter Klauer <contact>
Classes: 18 packages by
Country: Germany Germany
Innovation award
Innovation award
Nominee: 3x

Details
Using the ezcounter:

The counter generates an include file. Per default the name of the
file is "inc_vc.php". The content of "inc_vc.php" looks like this for
a visitcounter:

- 8< - - - - - - - - - - -

<?php
$arr = array();

$arr[] = '10.9.155.120; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)';
$arr[] = '10.9.155.110; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$arr[] = '10.9.155.102; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$arr[] = '10.9.186.56; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
$counter=4;
?>

- 8< - - - - - - - - - - -

The content of "inc_vc.php" looks like this for a hitcounter:

- 8< - - - - - - - - - - -

<?php
$counter=4;
?>

- 8< - - - - - - - - - - -

On a linux-apache system I used it successfully with this lines of code:

- 8< - - - - - - - - - - - 

include 'includes/inc_counter.php';
  
$c = new counter(VISITCOUNTER, 10 );
$c->putasdigits = true;
$c->digitclass = 'digits';
$c->put();

- 8< - - - - - - - - - - -

on a windows-iis system I had trouble using the same code as above.
The include file was not found from the script in all conditions and
created lots of error messages.
The solution was to set the absolute filepath of the counter-include-file
as the 3rd argument of the constructor. 

Here is my solution that finally worked:

- 8< - - - - - - - - - - -

include './includes/inc_counter.php';
  
$c = new counter(VISITCOUNTER, 10, 'D:\WebSites\includes\inc_vc.php');
$c->putasdigits = true;
$c->digitclass = 'digits';
$c->put();

- 8< - - - - - - - - - - -

If you set $c->putasdigits to true, then also define a css class for the digits
in the <head> section or in an external style sheet.
This example is for <head>-section-use:

- 8< - - - - - - - - - - -

<style type="text/css">
<!--
  .digits{
    background-color: black;
    color: lime;
    border: solid 1px lime;
  }
-->
</style>

- 8< - - - - - - - - - - -

This definitions are define()d in the class file:

HITCOUNTER   = 0
VISITCOUNTER = 1

Here are the vars that can be changed:

to be defined on creation time in the constructor:

  $c->countertype; // default = VISITCOUNTER;
  $c->visits;      // default = 10; # of different ip's before the oldest ip is thrown away  
  $c->counterfile; // default = './inc_vc.php';

this values can be changed or read after construction:
   
  $c->value;       // default = 0; // counter value
  $c->putasdigits; // default = false; // how to output the counter
  $c->mindigits;   // default = 4;
  $c->digitclass;  // default = ''; // name of css class for each of the digits
  $c->didcount;    // default = false; // true when the visitcounter counted the visitor

The visitcounter works without cookies. This is done with the array of ip's
which are written into the $c->counterfile. Set the number of $c->visits
to a reasonable value. 

  - If you have 1000 visits per day then set it to 100.
  - If you have 20 visits per day then set it to 5.

The oldest ip is thrown away after $c->visits other ip's were recognized.
You can calculate the value you need for $c->visits like this:

  visits = EVD / 24 * VH
 
EVD = estimated visits per day
VH  = visit hours: A visit lasts this amount of hours.

Assuming 1000 visits per day and a visit is 4 hours this is the formula:

  visits = 1000 / 24 * 4
  
The result would be 167.

  Files folder image Files  
File Role Description
Plain text file inc_counter.php Class Counter class file.
Accessible without login Plain text file liesmich.txt Doc. So wird die Klasse benutzt
Accessible without login Plain text file readme.txt Doc. How to use the class

 Version Control Unique User Downloads Download Rankings  
 0%
Total:1,818
This week:1
All time:2,092
This week:1,047Up
User Ratings User Comments (1)
 All time
Utility:69%StarStarStarStar
Consistency:72%StarStarStarStar
Documentation:66%StarStarStarStar
Examples:-
Tests:-
Videos:-
Overall:48%StarStarStar
Rank:2198