Page 1 of 1

hit counter to count unique hits only

Posted: Sat Apr 25, 2009 2:01 pm
by tomsace
Hey,
I have just got my hit counter working storing the hits into mysql.
The problem is it is counting every time the page is refreshed etc... I just want it to show unique visits.

Here is my code:

Code: Select all

<?php
$id=mysql_real_escape_string($_GET['id']);
//Adds one to the counter
mysql_query("UPDATE games SET hits = hits + 1");
 
//Retreives the current count
$count = mysql_fetch_row(mysql_query("SELECT hits FROM games WHERE id = '$id'"));
 
//Displays the count on your site
print "$count[0]";
?>
Any help apreciated.

Re: hit counter to count unique hits only

Posted: Sat Apr 25, 2009 4:01 pm
by McInfo
There is no way to know whether an anonymous hit is 100% unique, but there are some user attributes that you can use to narrow it down, like $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_USER_AGENT'], and cookies. If your users are logged in, it is a lot easier to identify unique hits.

Edit: This post was recovered from search engine cache.