Unique Ip Counter

So you want a unique Ip Counter huh? Well just scroll down and take a look, this should help you in one way or another.

<?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);
?>


Now since I don't have the time to explain everything in detail, I'm not gonna do it!! Now the code above is simple enough as in the filename = "hits.txt"; this basically means it writes the number of unique hits to the file specified. This file MUST be CHMODED to 777 and in the same directory as the php script. Now copy the code above into a blank file and hit "Save As" and save it as counter.php. Now create a new txt file and name it hits.txt save it as an empty txt and upload them together in the same directory and include them back via a PHP include like so:

<?php include('url/to/file/counter.php'); ?>


You may also put someting infront of it like:

Total Visitors: <?php include('url/to/file/counter.php'); ?>

and it will show up like Total Visitors: 3200 Well thats it for this tutorial, more to come soon. I hope this tutorial helped you either a little or alot.

Hosted by www.Geocities.ws

1