Open Notepad, create a blank dobument called
hits.txt. Now upload it to you website directory, make sure to put it in the same folder as the php page containing the hits code.
Also Note: You must CHMOD this file to 777 - This simply means that it doesn't need specific permissions for the file to execute.
Add the following code to a blank file and call it
counter.php.
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);
?> This simply tells it to add 1 pageview per IP, meaning it counts the amount of unique visitors you get.
This is then written to the
hits.txt file and increases every time the page is loaded by an alternative IP address.
Now to make this counter show up simply add the following code on any .php page:
Code:
Unique Visitors: <?php include("url/to/file/counter.php"); ?> NOTE: Remember to change
url/to/file/counter.php to the correct path of your counter.php file.