如何编写PHP代码记录搜索引擎爬虫访问记录?
- 内容介绍
- 文章标签
- 相关推荐
本文共计444个文字,预计阅读时间需要2分钟。
下面是简化后的开头内容:
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();}
下面是完整代码:
//记录搜索引擎爬行记录 $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中。
本文共计444个文字,预计阅读时间需要2分钟。
下面是简化后的开头内容:
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();}
下面是完整代码:
//记录搜索引擎爬行记录 $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中。

