The framework provides the ability to create persistent counter variables, whose value is automatically saved.
There are two types of counters variables: those with IP-check, which only change if the user with the current IP has not already been to the page within the last 3 hours. And those without IP check, which always change when called.
The following are some examples.
<?php
/* Create counter with IP-check */
$counter = new Counter("my_stats", YANA_COUNTER_USE_IP);
/* ... or: */
$counter = new Counter("my_stats");
/* Create counter without IP-check */
$counter = new Counter("my_stats", YANA_COUNTER_IGNORE_IP);
/* Increment counter "test1" */
$counter->count("test1");
/* Increment counter "test2", and save a description */
$counter->count("test2", "score");
/* Increment counter "test1" by 3 */
$counter->count("test1", "score", 3);
/* Decrement counter "test1" by 2 */
$counter->count("test1", "score", -2);
?>
<?php
$counter = new Counter("my_stats");
/* Get value of counter "test1" */
$int = $counter->getCount("test1");
/* Get description of counter "test1" */
$string = $counter->getInfo("test1");
print $string.":\t".$int;
/*
Output
score: 2
*/
/* get all counters */
$array = $counter->getCount("*");
foreach ($array as $a => $b)
{
print $a.":\t".$b;
}
?>
<!-- Insert this in your template file: --> <img src=[%"action=graphic_counter&target=0"|href%]>
The parameter "target" selects the background image. Valid values are the numbers 0-6.
Value of parameter "target" | Presentation |
---|---|
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 |
Thomas Meyer, www.yanaframework.net