PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Ming Choi   Count Class   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example file
Class: Count Class
Keep track of site visitors in a MySQL database
Author: By
Last change:
Date: 14 years ago
Size: 1,091 bytes
 

Contents

Class file image Download
<pre><?
// Count Class Example

include "count.class.php";

//Connect MySQL Database
$link = mysql_connect("127.0.0.1", "root", "mingming") or die("Fail to connect database");
mysql_select_db("test");

//call count class
//for visit count
$count = new Count(3600, 512, "Asia/Taipei", 8);

//for online count
//$count = new Online(3600, 512, 180, "Asia/Taipei", 8);

//Setup Table(s), for first time only
//var_dump($count->install());

//record for specific type, allow repeat count in the this page
$count->record("1", true);
$count->record("1", true);
$count->record("1", true);
$count->record("2", true);
$count->record("2", true);

//show the record, interval 3hours
var_dump($count->read(3*3600));

//show the max./min., interval 3hours
var_dump($count->analyseMaxMin(3*3600));
 
//find out the average count in each hour, needs at least a day record
var_dump($count->analyseAverage(86400, 3600));

//find out the average online in each weekday, needs at least a week record
var_dump($count->analyseAverage(604800, 86400));

mysql_close($link);
?>