PHP function code to determine whether the visitor is a search engine spider

高洛峰
Release: 2023-03-05 08:12:01
Original
2181 people have browsed it

/** 
* 判断是否为搜索引擎蜘蛛 
* 
* @author Eddy 
* @return bool 
*/ 
function isCrawler() { 
$agent= strtolower($_SERVER['HTTP_USER_AGENT']); 
if (!empty($agent)) { 
$spiderSite= array( 
"TencentTraveler", 
"Baiduspider+", 
"BaiduGame", 
"Googlebot", 
"msnbot", 
"Sosospider+", 
"Sogou web spider", 
"ia_archiver", 
"Yahoo! Slurp", 
"YoudaoBot", 
"Yahoo Slurp", 
"MSNBot", 
"Java (Often spam bot)", 
"BaiDuSpider", 
"Voila", 
"Yandex bot", 
"BSpider", 
"twiceler", 
"Sogou Spider", 
"Speedy Spider", 
"Google AdSense", 
"Heritrix", 
"Python-urllib", 
"Alexa (IA Archiver)", 
"Ask", 
"Exabot", 
"Custo", 
"OutfoxBot/YodaoBot", 
"yacy", 
"SurveyBot", 
"legs", 
"lwp-trivial", 
"Nutch", 
"StackRambler", 
"The web archive (IA Archiver)", 
"Perl tool", 
"MJ12bot", 
"Netcraft", 
"MSIECrawler", 
"WGet tools", 
"larbin", 
"Fish search", 
); 
foreach($spiderSite as $val) { 
$str = strtolower($val); 
if (strpos($agent, $str) !== false) { 
return true; 
} 
} 
} else { 
return false; 
} 
}
Copy after login

You can find a lot of them on the Internet, but they are all copied and copied in the same way, and they are not comprehensive enough. I have compiled a more comprehensive code here:

function is_spider(){ 
$robot = 0; 
$USER_AGENT = strtolower($_SERVER['HTTP_USER_AGENT']); 
if(strpos($USER_AGENT,"bot")) $robot = 1; 
if(strpos($USER_AGENT,"spider")) $robot = 1; 
if(strpos($USER_AGENT,"slurp")) $robot = 1; 
if(strpos($USER_AGENT,"mediapartners-google")) $robot = 1; 
if(strpos($USER_AGENT,"fast-webcrawler")) $robot = 1; 
if(strpos($USER_AGENT,"altavista")) $robot = 1; 
if(strpos($USER_AGENT,"ia_archiver")) $robot = 1; 
if($robot == 1){ 
//do something 
} 
return ''; 
}
Copy after login

More PHP judgments For related articles on whether the visitor is a search engine spider’s function code, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!