使用WordPress蜘蛛记录来生成这个功能。在对网站优化的研究中,清楚地了解蜘蛛的爬行规律也非常重要,这样才能了解蜘蛛的爬行规律。按照这个规则,我们会重新写文章,这符合蜘蛛的胃口,非常有利于优化。今天分享一下实现WordPress博客蜘蛛爬行记录统计教程。

将下方代码放入function.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权限,查看统计的方式就是这样 https://域名/robotslogs.txt

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部