Bot View Counter in PHP

On the counter pages:

  • 60 Unique Visitors
  • 180 Page Views
  • 18 Bot Views
  • 289,734 Unique Visitors
  • 384,204 Page Views
  • 99,136 Bot Views

Sometimes your site gets a lot of traffic, but it's not traffic coming from real people.

This addition to the Unique Visitor Counter and Pageview Counter is an extra counter category that only counts views from bots.

289.7K visitors 384.2K views 99.1K bots

Source Code

Note: This is a function that you can wrap around code to only apply if the user agent detects a bot from a list of known bots.

PHP

// Function to check if the user agent is a bot
function isBot($userAgent) {
$bots = [
'Googlebot',
'Bingbot',
'Slurp',
'DuckDuckBot',
'Baiduspider',
'YandexBot',
'Sogou',
'Exabot',
'Facebot',
'ia_archiver',
'Twitterbot',
'LinkedInBot',
'Applebot',
'AhrefsBot',
'SemrushBot',
'MJ12bot',
'DotBot',
'BLEXBot',
'Coccinelle',
'BingPreview',
'MetaGer',
'Grapeshot',
'NuzzelBot',
'Screaming Frog SEO Spider',
'W3C Validator',
'Archive.org Bot',
'ChatGPT', // AI Bot
'Bard', // AI Bot
'Claude', // AI Bot
'Jasper', // AI Bot
'Copy.ai', // AI Bot
'DeepAI', // AI Bot
'OpenAI API', // AI Bot
'Replika', // AI Bot
'Kuki', // AI Bot
'Cleverbot', // AI Bot
'Yandex', // Russian Search Engine
'Baidu', // Chinese Search Engine
'Ahrefs', // SEO Tool
// 'Moz', // SEO Tool
'SEMrush', // SEO Tool
'Netcraft', // Internet Services
'Quantcast', // Audience Measurement
'StatCounter', // Web Analytics
'Google PageSpeed Insights', // Performance Analysis
'Google Analytics',
'Piwik',
'Clicky',
'Sucuri',
'Cloudflare',
'Qualys',
'BingImageCreator', // Additional Bot
'PinterestBot', // Additional Bot
'Slackbot', // Additional Bot
'Google AdsBot' // Additional Bot
];
foreach ($bots as $bot) {
if (stripos($userAgent, $bot) !== false) {
return true;
}
}
return false;
}

// Proceed only if the user agent is a bot
if (isBot($_SERVER['HTTP_USER_AGENT'])) {

}