File based page counter
<!-- Create an empty file myData.dat first -->
<?php
$cfile = "myData.dat";
$fh = fopen($cfile, "r+");
if (!$fh){
die("<BR>Failed to open file <I>$cfile</I>.");
}
$s = fgets($fh, 6);
$count = (int) $s;
$count = $count + 1;
$count = str_pad($count, 6);
rewind($fh);
fwrite($fh, $count);
echo "$count";
fclose($fh);
?>
Related examples in the same category