写博客也有一段时日了,为何搜寻引擎迟迟不收录你的页面呢?想晓得每天都有哪些蜘蛛“会晤”你的网站吗?作为一名wordpress用户,有紧要晓得每天都有哪些蜘蛛爬行过你的网站,以便于明了各搜寻引擎蜘蛛爬行频率,对网站发展针对性的SEO美化。
的确很容易,只要增进以下代码,而后再调用文件代码就OK了,是否是很利便呢?那就开始动作吧。
曩昔我也找过几个蜘蛛爬行记录工具PHP版,后果都不尽人意。并且这些PHP步骤大多要发展安设,还要将蜘蛛爬行记录增进到MYSQL中,难免太贫苦。那就探究一个繁难的蜘蛛爬行记录器吧~

googlebot
1.起首,在wordpress主题根目录创立一个robots.php文件,写入以下形式:
<?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, \’搜狐-search\’) !== false){
return \’Sohubot\’;
}
if (strpos($useragent, \’lycos\’) !== false){
return \’Lycos\’;
}
if (strpos($useragent, \’robozilla\’) !== false){
return \’Robozilla\’;
}
return false;
}
function nowtime(){
$date=gmdate(\”Y-n-j H:i:s\”,time()+8*3600);
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\”);
fwrite($data,\”Time:$time robot:$searchbot URL:$tlc_thispage\\n\”);
fclose($data);
}
?>
将其上传于你的主题目录内。
2.在Footer.php或header.php的适当地位增进以下代码调用robots.php。
<?php include(\’robots.php\’) ?>
步骤原理:通过对蜘蛛标识符(如Baiduspider、Googlebot)的果断,记录蜘蛛爬行时日,并天生日志文件robotslogs.txt于根目录。
步骤害处:无法记录蜘蛛爬行的页面,听命较为容易。
转载请阐明:
(责任编辑:admin)