Page Hits Counter





6
Date Submitted Mon. Feb. 12th, 2007 7:00 PM
Revision 1 of 1
Helper snowdonkey
Tags "hits counter" | cookies | PHP
Comments 2 comments
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>";
?>
 

Bennett Joseph

Comments

Comments Inaccurate Count
Wed. Feb. 21st, 2007 5:29 PM    Helper Idlemind
  Comments Intended Functionality
Mon. Apr. 9th, 2007 10:36 PM    Helper snowdonkey

Voting