1.Create a .txt file, say hit.txt.
2. Enter the value 0 in hit.txt and save.
3. Create a php file, say counter.php with the following code…
$filename= "hits.txt" ;
$fd = fopen ($filename , "r") or die ("Can't open $filename") ;
$fstring = fread ($fd , filesize ($filename)) ;
echo "$fstring" ;
fclose($fd) ;
$fd = fopen ($filename , "w") or die ("Can't open $filename") ;
$fhits = $fstring + 1 ;
$fout= fwrite ($fd , $fhits ) ;
fclose($fd) ;
?>
4. Include the counter.php file wherever you want to display the number of hits.

Twitter
LinkedIn