WordPress 添加搜索引擎蜘蛛爬虫记录

之前 小羿 给大家发过「利用 WordPress 更新服务功能,加快 搜索引擎 收录」但是怎么样才知道 搜索引擎 有没有来访问过网站呢?我们需要爬虫记录,下面教大家给 WordPress 添加搜索引擎蜘蛛爬虫记录

后台」→「外观」→「编辑」→ 「functions.php」文件,把下面的代码添加进去:

//统计蜘蛛
function get_naps_bot(){
$useragent = strtolower($_SERVER['HTTP_USER_AGENT']);
if (strpos($useragent, 'googlebot') !== false){
return 'Googlebot';
}
if (strpos($useragent, 'msnbot') !== false){
return 'MSNbot';
}
if (strpos($useragent, 'slurp') !== false){
return 'Yahoobot';
}
if (strpos($useragent, 'baiduspider') !== false){
return 'Baiduspider';
}
if (strpos($useragent, 'sohu-search') !== false){
return 'Sohubot';
}
if (strpos($useragent, 'lycos') !== false){
return 'Lycos';
}
if (strpos($useragent, 'robozilla') !== false){
return 'Robozilla';
}
return false;
}
function nowtime(){
date_default_timezone_set('Asia/Shanghai');
$date=date("Y-m-d.G:i:s");
return $date;
}
$searchbot = get_naps_bot();
if ($searchbot) {
$tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']);
$url=$_SERVER['HTTP_REFERER'];
$file="robotslogs.txt";
$time=nowtime();
$data=fopen($file,"a");
$PR="$_SERVER[REQUEST_URI]";
fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n page:$PR\r\n");
fclose($data);
}

然后在网站建立 robotslogs.txt 文件,并且设置权限为777,输入 你的网站/robotslogs.txt 就可以看蜘蛛爬虫记录了。(首次访问可能没记录,需要等待蜘蛛爬后,才会有记录)

# 更多WordPress技巧,请关注「WordPress专题

方法来源:dedewp