Counters
|
|
|
|
<?php /*
Lexike NamedCounter kezel�je phpben :)
*/ $counterfile = "./ncounter.txt"; $countercontent = array();
function readcounterfile()
{
global $counterfile, $countercontent;
$tempcontent = file ($counterfile);
foreach ($tempcontent as $key => $value)
{
// �t�rni
$value = trim($value);
$location = strpos($value, "=");
$key = trim(substr($value, 0, $location - 1));
$value = trim(substr($value,$location+1, strlen($value) - $location ) );
$countercontent[$key] = $value;
} // foreach
return (0);
} // readcounterfile
function writecounterfile()
{
global $counterfile, $countercontent;
$filehandler = fopen ($counterfile, "w");
reset ($countercontent);
foreach ($countercontent as $key => $value)
{
fwrite ($filehandler, $key." = ".$value."n");
} // fireach
fclose($filehandler);
return (0);
} // writecounterfile
function setcounter ($countername, $newvalue)
{
global $countercontent;
readcounterfile();
$countercontent[$countername] = $newvalue;
writecounterfile();
return ($newvalue);
} // setcounter
function getcounter($countername)
{
global $counterfile, $countercontent;
readcounterfile();
if (in_array($countername, array_keys($countercontent)))
{
return ($countercontent[$countername]);
}
else
{
return ($countercontent[$countername] = 0);
}
} // get_counter
function inccounter($countername)
{
return (setcounter($countername, getcounter($countername)+1));
} // inccounter
function deccounter($countername)
{
return (setcounter($countername, getcounter($countername)-1));
} // deccounter
?>
|
|
|
Usage Example
|
deccounter() decrease
inccounter() increase
setcounter() setting initial value
getcounter() get counter value or -if not present-create a new counter
using:
setting $counterfile value is the
filename of counter.
$foo = inccounter("tester");
echo $tester."<br>";
the form of stored counters file:
name1 = value2
name2 = value2
|
|
|
Rate This Script
|
|
|
|