UpateStatistics

[insert_php]

function writeCounts($counts) {
$ser = serialize($counts);
$countfile = fopen(„counts.txt“, „w“) or die(„Unable to open file!“);
fwrite($countfile, $ser);
fclose($countfile);
}

function readCounts() {
$countfile = fopen(„counts.txt“, „r“) or die(„Unable to open file!“);
$ser = fread($countfile , filesize(„counts.txt“));
fclose($countfile );
$counts = unserialize($ser);
return $counts;
}

function initializeCounts() {
$counts = array(
„1“ => 0,
„2“ => 0,
„3“ => 0,
„4“ => 0,
„5“ => 0,
„6“ => 0,
„7“ => 0,
„8“ => 0,
);

writeCounts($counts);
}

function updateCounts() {
$counts = readCounts();

$key = $_GET[‚link‘];

if (!array_key_exists ($key, $counts)) {
echo ‚invalid key:‘ . $key;
return;
}

echo $counts[$key] . „
„;

$counts[$key] = $counts[$key] + 1;
writeCounts($counts);
}

updateCounts();

[/insert_php]