I’m trying to make my view count only counting unique visitors.
In my Item Controller of Cakephp 2.x I have the following:
function view($slug = null) {
[...]
$this->Item->updateAll(
array('Item.hits'=>'Item.hits+1'),
array('Item.slug'=>$slug)
);
}
This adds +1 to the hit column and works fine.
The flaw is, that clicking the view many times increases the count.
Any idea how I could make a unique count?
Thanks in advance
quick solution
This sets a unique session for each item viewed, based on the slug.
If the session does not already exist, the user hasn’t viewed the article, so increase the hit and then set the session.
If the session does already exist; don’t update it again.
This means that one user can’t increase the hits per item, more than once in any one session, which is about as good as you’ll get in a few lines of code.
Anything more accurate will take a lot of effort and it’s likely just not worth it.