by Hiroshi on June 13th, 2008

This PHP hit counter counts unique hits and writes down all the IP addresses from hits. We need two files for this script.

1- Text blank file (hits.php)
2- PHP script file

Creating PHP Unique Hit Counter – Code

<?php
$filename = "hits.txt" ;
 
$file = file($filename);
$file = array_unique($file);
$hits = count($file);
echo $hits;
 
$fd = fopen ($filename , "r");
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;
$fd = fopen ($filename , "w");
$fcounted = $fstring."\n".getenv("REMOTE_ADDR");
$fout= fwrite ($fd , $fcounted );
fclose($fd);
?>

Unique Counter

  • Share/Bookmark

,

Leave a Review