sandip
answered Nov 30 '-1 00:00
if bot had made request to the page than $_SERVER['HTTP_USER_AGENT'] contain like this value :
Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)
Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.97 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
so to parse it , following is the code will print the bot name :
if(strstr(strtolower($_SERVER['HTTP_USER_AGENT']), "bot"))
{
$a=explode(";",$stats['user_agent']);
if($a[count($a)-2]!=''){
echo $a[count($a)-2];
}
else {
$a=explode(" ",$stats['user_agent']);
if($a[count($a)-2]!=''){
echo $a[count($a)-2];
}else{
echo "bot";
}
}