I am trying to create a simple Hit Counter using Kohana3 and PHP. But when I load a page with it, it counts as 1-3 times (normally, the first hit 3, then 2, then 1).
The code I’m using:
$game = ORM::factory('game')
->find_by_slug($slug);
if(!$game->loaded())
{
$this->request->redirect('/',404);
}
$game->times_played++;
$game->save();
An example page: http://www.plugb.com/game/qrossfire EDIT: Number of times played is below description.
How can I solve this?
Thank you.
EDIT:
I’ve found some requests like this:
/game/qrossfire
Agent: facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
/game/stickmen-swat
Agent: facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)
/game/qrossfire
Agent: MetaURI API +metauri.com
Have a look at the requests your browser is making, and check that it’s not somehow making more than one to that page.
You might have some other files in the page (e.g. images etc) matching that route.
You can check both the client side (with addons like Firebug) and the serverside (by watching the webserver access log)