Page Hits Counter
6
A simple page hits counter that uses a single cookie to tell the user how many times they have visited the page.
<?php
// If it's the user's first visit set the count to 1
if(!$_COOKIE["pageCounter"]) $count = 1;
// If they've been here before, then add 1 to their visit count
else $count = $_COOKIE["pageCounter"] + 1;
// Make a year-long cookie that whose starts at 1or replace the old one with the current count
setcookie("pageCounter", "$count", time()+60*60*24*365);
echo "<p>You've viewed this page " . $count . " times.</p>";
?>






For the very reason that the script uses a cookie (so that it can remember the visit count for a long time), means that if two different pages reference the same script (use the same cookie), the count will be inaccurate.
It was assumed that you would rename the cookie for each page you wanted to keep a count for. For example: you home page counter would be $_COOKIE["home"], your contact page would be $_COOKIE["contact"], etc.
I'm sorry this wasn't obvious, but the script works as intended, and should meet your needs once you know how to use it.