Bob's Hobby Bob's Hobby blog

4L hit counter script

4L hit counter is a very simple text based hit counter.It uses only 4 lines of PHP code.Place this script into webpage (e.g. sidebar.php for wordpress template or in a specific page as you need).This script will count the number of times a page is called and store this number into a simple text file(e.g. hits.txt).

<?php
$hitfile = $_SERVER['DOCUMENT_ROOT']."/counter/hits.txt";
$hits = @file_get_contents($hitfile);
file_put_contents($hitfile,$hits+1,LOCK_EX);
echo ($hits+1);
?>

To use the script above you need to create a folder "counter" and chmod to 0755.