Skip to content

Instantly share code, notes, and snippets.

@merouanekhalili
Created April 20, 2013 14:56
Show Gist options
  • Save merouanekhalili/5426250 to your computer and use it in GitHub Desktop.
Save merouanekhalili/5426250 to your computer and use it in GitHub Desktop.
PHP : detect bot
<?php
public function isBot() {
$bots = array(
'googlebot',
'adsbot-google',
'feedfetcher-google',
'yahoo',
'lycos',
'bloglines subscriber',
'dumbot',
'sosoimagespider',
'qihoobot',
'fast-webcrawler',
'superdownloads spiderman',
'linkwalker',
'msnbot',
'aspseek',
'webalta crawler',
'youdaobot',
'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'
);
foreach($bots as $bot) {
if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), trim($bot)) !== false) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment