下面是完整代码:
//记录搜索引擎爬行记录 $searchbot = get_naps_bot(); if ($searchbot) { $tlc_thispage = addslashes($_SERVER['HTTP_USER_AGENT']); $url = $_SERVER['HTTP_REFERER']; $file = WEB_PATH.'robotslogs.txt'; $date = date('Y-m-d H:i:s'); $data = fopen($file,'a'); fwrite($data,"Time:$date robot:$searchbot URL:$tlc_thispage/r/n"); fclose($data); }
WEB_PATH为index.PHP下define的根目录路径,意思就是说robotslogs.txt文件是放在根目录下的。
通过get_naps_bot()
获取蜘蛛爬行记录,然后在通过addslashes处理一下,将数据存储于变量$tlc_thispage中。
fopen打开robotslogs.txt文件,将数据通过函数fwrite写入,在通过函数fclose关闭就可以了。
因为我觉得没必要,所以把自己网站上的代码删除了,所以也没有效果示例了。
PS:php获取各搜索蜘蛛爬行记录的代码
支持如下的搜索引擎:Baidu,Google,Bing,Yahoo,Soso,Sogou,Yodao爬行网站的记录!
代码:
<?php /** * 获取搜索引擎爬行记录 * edit by www.cnhackhy.com */ function get_naps_bot() { $useragent = strtolower($_SERVER['HTTP_USER_AGENT']); if (strpos($useragent, 'googlebot') !== false){ return 'Google'; } if (strpos($useragent, 'baiduspider') !== false){ return 'Baidu'; } if (strpos($useragent, 'msnbot') !== false){ return 'Bing'; } if (strpos($useragent, 'slurp') !== false){ return 'Yahoo'; } if (strpos($useragent, 'sosospider') !== false){ return 'Soso'; } if (strpos($useragent, 'sogou spider') !== false){ return 'Sogou'; } if (strpos($useragent, 'yodaobot') !== false){ return 'Yodao'; } return false; } function nowtime(){ $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="www.cnhackhy.com.txt"; $time=nowtime(); $data=fopen($file,"a"); fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n"); fclose($data); } ?>
总结
以上所述是小编给大家介绍的php记录搜索引擎爬行记录,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对华域联盟网站的支持!
您可能感兴趣的文章:
- PHP中使用ElasticSearch最新实例讲解
- PHP ElasticSearch做搜索实例讲解
- php获取从百度、谷歌等搜索引擎进入网站关键词的方法
- php实现判断访问来路是否为搜索引擎机器人的方法
- PHP记录搜索引擎蜘蛛访问网站足迹的方法
- 使用php显示搜索引擎来的关键词
- 解析PHP对现有搜索引擎的调用
- php操作ElasticSearch搜索引擎流程详解
本文由 华域联盟 原创撰写:华域联盟 » php记录搜索引擎爬行记录的实现代码
转载请保留出处和原文链接:https://www.cnhackhy.com/44949.htm