Counter Visits Anti Bot Sharing Facebook

Asked

Viewed 37 times

1

I created a counter of visits, but, we need that there is no count through the visits for reading the bots, mainly of facebook.

This code is called via Ajax, after the user is on the page by 5 seconds.

Even so, when sharing the page and facebook read the information, still a visit is accounted for.

    $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';
    }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.