Is there a way, via PHP, to know that who is visiting my page is Google bot and Facebook bot?
Is there a way, via PHP, to know that who is visiting my page is Google bot and Facebook bot?
if (strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "googlebot")) {
// Provavelmente proveio do google.
// Aqui você implementa as suas firulas.
}
if (
strpos($_SERVER["HTTP_USER_AGENT"], "facebookexternalhit/") !== false ||
strpos($_SERVER["HTTP_USER_AGENT"], "Facebot") !== false
) {
// Provavelmente proveio do facebook.
// Aqui você implementa as suas firulas.
}
Note: Be aware that HTTP_USER_AGENT is easy to manipulate. Anyone can create a script that identifies itself as googlebot , for example. So do not trust 100% in this parameter.
To ensure greater integrity you will have to do reverse DNS checks, IP source, etc.