迅睿CMS框架是一款PHP8高性能·简单易用的CMS开源开发框架,基于MIT开源许可协议发布,免费且不限制商业使用,是免费开源的产品,以万端互联为设计理念,支持的微信公众号、小程序、APP客户端、移动端网站、PC网站等多终端式管理系统。
联系官方销售客服
1835022288
028-61286886
模板标签里面
怎么在模板中判断是否是蜘蛛访问,如果是蜘蛛访问就展现其他的内容,不是的就正常内容。 有判断代码吗?
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 ''; }
function isCrawler() { echo $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; } } if (isCrawler()){ echo "你好蜘蛛精!"; } else{ echo "你不是蜘蛛精啊!"; }