Plain simple script to keep track of the page hits.
PHP Example :
<?
$STAT_HITS = "../hitsperpage.txt";
$PAGE = pathinfo($_SERVER["PHP_SELF"]);
$BASENAME = substr($PAGE["basename"], 0, strlen($PAGE["basename"]) - 4);
/*
$BASENAME is filename without directories and extension
$STAT_HITS is a flat text file with filenames without directories and extension and number of hits on that page (delimiter is "|") so for example:
index|199|
See the script in action on www.vincentpeters.nl
*/
logHitsperpage($STAT_HITS,$BASENAME);
function logPagehits($STAT_HITS,$BASENAME){
$file = file("$STAT_HITS");
$match = false;
$sOut = "";
for($x=0;$x<sizeof($file);$x++){
$arrRec = explode("|",$file[$x]);
$t = $arrRec[0];
if($t == $BASENAME){
$match = true;
$arrRec[1]++;
}
$sOut .= $arrRec[0]."|".$arrRec[1]."|rn";
}
if($match == false){ // if entry does not exist add new entry with one (1) hit
$sOut .= $BASENAME."|1|rn";
}
$outFile = fopen("$STAT_HITS", "w");
fputs($outFile,$sOut);
fclose($outFile);
}
?>