php记录搜索引擎爬行记录的实现代码

作者:mrr 时间:2024-05-11 09:19:14 

下面是完整代码:


//记录搜索引擎爬行记录 $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.aspxhome.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.aspxhome.com.txt";
$time=nowtime();
$data=fopen($file,"a");
fwrite($data,"Time:$time robot:$searchbot URL:$tlc_thispage\n");
fclose($data);
}
?>

总结

以上所述是小编给大家介绍的php记录搜索引擎爬行记录网站的支持!

标签:php,搜索引擎
0
投稿

猜你喜欢

  • 详解MySQL数据库中字符串的正确使用

    2010-06-20 15:01:00
  • JavaScript中callee和caller的区别与用法实例分析

    2024-04-10 13:59:35
  • MySQL优化方案参考

    2024-01-24 03:28:03
  • 详解Python OpenCV图像分割算法的实现

    2022-11-28 13:15:44
  • Python3 hashlib密码散列算法原理详解

    2021-07-06 12:59:55
  • Python爬虫辅助利器PyQuery模块的安装使用攻略

    2023-10-18 02:19:34
  • Python3 Random模块代码详解

    2023-04-11 01:36:20
  • set rs=server.CreateObject("adodb.recordset") 的中文详细说明

    2011-03-06 11:21:00
  • 页面加载对访问的影响

    2009-10-30 18:54:00
  • Python人工智能之路 jieba gensim 最好别分家之最简单的相似度实现

    2023-07-20 09:20:03
  • GO语言不固定参数函数与匿名函数的使用

    2024-02-17 14:42:17
  • Vue项目中使用setTimeout存在的潜在问题及解决

    2024-05-28 16:00:14
  • 关于JavaScript中的this指向问题总结篇

    2024-04-29 13:21:25
  • MySQL获取所有分类的前N条记录

    2024-01-21 09:39:27
  • 封装2个ajax函数

    2010-09-03 18:14:00
  • 使用绿色版SQLServer2008R2出现的问题解析

    2024-01-22 23:42:58
  • 如何解决python多种版本冲突问题

    2023-12-28 06:41:17
  • Python3的进程和线程你了解吗

    2023-05-19 00:33:30
  • ExtJS 开发总结

    2009-04-28 13:05:00
  • Python Socket多线程并发原理及实现

    2022-09-05 08:21:07
  • asp之家 网络编程 m.aspxhome.com