PHP Classes

File: readme.txt

Recommend this page to a friend!
  Classes of Peter Klauer   ezcounter   readme.txt   Download  
File: readme.txt
Role: Documentation
Content type: text/plain
Description: How to use the class
Class: ezcounter
User visit or hit counter without cookies
Author: By
Last change: minor
Date: 20 years ago
Size: 3,464 bytes
 

Contents

Class file image Download
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.