PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
<?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.
Last edited by Benjamin on Sat Apr 25, 2009 2:33 pm, edited 1 time in total.
Reason:Changed code type from text to php.
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.