关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

PHP检测搜索引擎蜘蛛访问的真实性代码

发布时间:2019-11-28 18:22:18
<?phpif(getspider()){
exit('假的搜索引擎!');}function getspider(){
$访问UA = strtolower($_SERVER['HTTP_USER_AGENT']);
  $访问IP = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
  if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
  $list = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
  $访问IP = $list[0];
  }
  if (!ip2long($访问IP)) $访问IP = '未知IP';
$访问主机 = str_replace('.', '-', $访问IP);
if (strpos($访问UA, 'googlebot') !== false){
$解析主机 = gethostbyaddr($_SERVER['REMOTE_ADDR']);
if ($解析主机 != 'crawl-'.$访问主机.'.googlebot.com') return 'googlebot?';
}

if (strpos($访问UA, 'sogou') !== false){
$解析主机 = gethostbyaddr($_SERVER['REMOTE_ADDR']);
if ($解析主机 != 'sogouspider-'.$访问主机.'.crawl.sogou.com') return 'sogou';
}
if (strpos($useragent, 'bing') !== false){
$解析主机 = gethostbyaddr($_SERVER['REMOTE_ADDR']);
if ($解析主机 != 'msnbot-'.$访问主机.'.search.msn.com') return 'bing';
}
if (strpos($访问UA, 'baiduspider') !== false){
$解析主机 = gethostbyaddr($_SERVER['REMOTE_ADDR']);
if ($解析主机 != 'baiduspider-'.$访问主机.'.crawl.baidu.com') return 'baiduspider?';
}
return false;}

/template/Home/Zkeys/PC/Static