Create a bare-bones PHP Hit Counter
1. To allow php embedded inside html to run, you must create file .htaccess and store it in your root Folder
.htaccess (text file)
Contents: AddHandler x-httpd-php .html .htm .cgi .php
2. Embed PHP script in each HTML file.
Contents:
<?php include("hitcounter.php"); ?>
3. Create, one occurance per folder, Filename: hitcounter.php
Contents:
<?php
$filename = "hitcounter.txt";
$count= file($filename);
$count[0]++;
$file = fopen ($filename, "w") or die ("Cannot find $filename");
fputs($file, "$count[0]");
fclose($file);
echo $count[0];
?>
4. Create, one occurance per folder, Filename: hitcounter.txt
Contents: 1
This means each HTML file must be inside its own folder. Alternatively, each occurence of file-pairs hitcounter.php and hitcounter.txt must have different filenames to differentiate them within the same Folder.
Source Link