Php checks whether a visitor is a search engine spider's function code. For more information, see. Php checks whether a visitor is a search engine spider's function code. For more information, see.
The code is as follows:
/**
* Determine whether it is a search engine spider
*
* @ 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 )",
"Baidusp ",
"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;
}
}
I can find the ghost plug on the Internet, but it is not comprehensive enough to copy all the copies. here I have compiled a comprehensive code:
The code is as follows:
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 '';
}