Reputation: 1203
When I paste my website link at a social network (Facebook or Twitter for example), the social network access my site to show a preview to the user.
I want to separate this access from real access at my reports, but to do this, I need to identify this cases.
This kind of access send any kind of information that is default for everysite that I can identify that this access is not a real user, but a robot?
Upvotes: 10
Views: 965
Reputation: 13173
You can use the User-Agent to do that.
if (strpos($_SERVER["HTTP_USER_AGENT"], "Twitterbot") !== false)
echo "TwitterBot";
else if (strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit") !== false)
echo "Facebook";
else
echo "regular user";
https://developers.facebook.com/docs/sharing/webmasters/crawler
Upvotes: 2
Reputation: 1212
You should be able to identify those robots from their user-agent string. For example, Twitter uses the User-Agent of Twitterbot. And Facebook crawler identification is documented here.
Upvotes: 8