PHP Unique Hit Counter Script

by Hiroshi on June 13, 2008

in Hit Counter II

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

Related Posts

Previous post:

Next post: