本文主要和大家介绍了php记录搜索引擎爬行记录的实现代码,然后在文中给大家补充介绍了php获取各搜索蜘蛛爬行记录的代码,需要的朋友可以参考下,希望能帮助到大家。
下面是完整代码:
//记录搜索引擎爬行记录 $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.jb51.net
*/
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.jb51.net.txt";
$time=nowtime();
$data=fopen($file,"a");
fwrite($data,"time:$time robot:$searchbot url:$tlc_thispage\n");
fclose($data);
}
?>
相关推荐:
jquery jsonp跨域模拟搜索引擎实例分享
php 对现有搜索引擎的调用详解
关于javascript如何切换搜索引擎的导航网页搜索框的实例代码分享
以上就是php实现搜索引擎爬行代码分享的详细内容。