Skip to content

Instantly share code, notes, and snippets.

@ScottPhillips
Created June 10, 2012 08:15
Show Gist options
  • Save ScottPhillips/2904459 to your computer and use it in GitHub Desktop.
Save ScottPhillips/2904459 to your computer and use it in GitHub Desktop.
Detects a few common Search Bots
<?php
/* Detects some common web bots */
function detectBot($USER_AGENT) {
$crawlers_agents = strtolower('Bloglines subscriber|Dumbot|Sosoimagespider|QihooBot|FAST-WebCrawler|Superdownloads Spiderman|LinkWalker|msnbot|ASPSeek|WebAlta Crawler|Lycos|FeedFetcher-Google|Yahoo|YoudaoBot|AdsBot-Google|Googlebot|Scooter|Gigabot|Charlotte|eStyle|AcioRobot|GeonaBot|msnbot-media|Baidu|CocoCrawler|Google|Charlotte t|Yahoo! Slurp China|Sogou web spider|YodaoBot|MSRBOT|AbachoBOT|Sogou head spider|AltaVista|IDBot|Sosospider|Yahoo! Slurp|Java VM|DotBot|LiteFinder|Yeti|Rambler|Scrubby|Baiduspider|accoona');
$crawlers = explode("|", $crawlers_agents);
if(is_array($crawlers) {
foreach($crawlers as $crawler) {
if (strpos(strtolower($USER_AGENT), trim($crawler)) !== false) {
return true;
}
}
}
return false;
}
//Usage:
if(detectBot($_SERVER['HTTP_USER_AGENT'])) {
echo "You're A BOT";
} else {
echo "You're NOT A BOT";
}
@raza-hasnain
Copy link

raza-hasnain commented Jun 1, 2016

Nice
is there any option to detect bad bots ?
I am running a website, I get thousands of spammers on my website : www.funkodia.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment