如何记录搜索引擎爬行记录php版

写博客也有一段时间了,为什么搜索引擎迟迟不收录你的页面呢?想知道每天都有哪些蜘蛛“拜访”你的网站吗?作为一名网站长,有必要知道每天都有哪些蜘蛛爬行过你的网站,以便于了解各搜索引擎蜘蛛爬行频率,对网站进行针对性的SEO优化,因此我们需要了解搜索引擎爬行记录。

其实很简单,只要添加以下代码,然后再调用文件代码就OK了,是不是很方便呢?那就开始行动吧。

之前我也找过几个蜘蛛爬行记录工具PHP版,结果都不尽人意。而且这些PHP程序大多要进行安装,还要将蜘蛛爬行记录添加到MYSQL中,未免太麻烦。那就寻找一个简易的搜索引擎爬行记录工具把~

<?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=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'];
    $script=$_SERVER['SCRIPT_URI'];    
    $file="robotslogs.txt";
    $time=nowtime();
    $data=fopen($file,"a");
    fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage SCRIPT:$script 
");
    fclose($data);
}
?>

 附上源码:http://files.cnblogs.com/mengdejun/se.zip

在Footer.php或header.php的适当位置添加以下代码调用robots.php。

转载请注明:白开水的博客 x

原文地址:https://www.cnblogs.com/mengdejun/p/se_record.html