We created a hit counter, but we need no counting through the visits to read bots, especially from facebook.
This code is called via ajax, after the user has been on the page for 5 seconds.
But even so, when sharing the page and facebook read the information, a visit is still booked.
$contador = &$_COOKIE['contador'.$album_id];
if ( !$contador )
{
if (preg_match('~(bot|crawl)~i', $_SERVER["HTTP_USER_AGENT"])) {
echo 'bot';
} else {
if (
strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/") !== false ||
strpos($_SERVER["HTTP_USER_AGENT"], "Facebot") !== false
)
{
echo 'bot';
}
else
{
setcookie('contador'.$album_id, true, time() + ( 3600*24*7 ) );
//insert no banco
}
}
}
else
{
echo 'ja visitou';
}
}