Created
June 10, 2012 08:15
-
-
Save ScottPhillips/2904459 to your computer and use it in GitHub Desktop.
Detects a few common Search Bots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"; | |
} |
Hi,
Avoid the foreach, because is will impact the performance, instead use a preg_match().
Take a look here https://gist.github.com/Exadra37/9453909
In line 6, you forgot a bracket. ;)
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
replace if(is_array($crawlers) {
with if(is_array($crawlers)) {
;) thanks.