温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PHP如何记录搜索引擎蜘蛛访问网站足迹

发布时间:2021-09-02 11:45:51 阅读:179 作者:小新 栏目:开发技术
PHP开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

这篇文章给大家分享的是有关PHP如何记录搜索引擎蜘蛛访问网站足迹的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

具体分析如下:

搜索引擎的蜘蛛访问网站是通过远程抓取页面来进行的,我们不能使用JS代码来取得蜘蛛的Agent信息,但是我们可以通过image标签,这样我们就可以得到蜘蛛的agent资料了,通过对agent资料的分析,就可以确定蜘蛛的种类、性别等因素,我们在通过数据库或者文本来记录就可以进行统计了。

数据库结构:

以下为引用的内容:

#
# 表的结构 `naps_stats_bot`
#

CREATE TABLE `naps_stats_bot` (
`botid` int(10) unsigned NOT NULL auto_increment,
`botname` varchar(100NOT NULL default '',
`botagent` varchar(200NOT NULL default '',
`bottag` varchar(100NOT NULL default '',
`botcount` int(11NOT NULL default '0',
`botlast` datetime NOT NULL default '0000-00-00 00:00:00',
`botlasturl` varchar(250NOT NULL default '',
UNIQUE KEY `botid` (`botid`),
KEY `botname` (`botname`)
) TYPE=MyISAM AUTO_INCREMENT=9 ;
#
# 导出表中的数据 `naps_stats_bot`
#
INSERT INTO `naps_stats_bot` VALUES (1'Googlebot''Googlebot/2.X (+http://www.googlebot.com/bot.html)''googlebot'0'0000-00-00 00:00:00''');
INSERT INTO `naps_stats_bot` VALUES (2'MSNbot''MSNBOT/0.1 (http://search.msn.com/msnbot.htm)''msnbot'0'0000-00-00 00:00:00''');
INSERT INTO `naps_stats_bot` VALUES (3'Inktomi Slurp''Slurp/2.0''slurp'0'0000-00-00 00:00:00''');
INSERT INTO `naps_stats_bot` VALUES (4'Baiduspider''Baiduspider+(+http://www.baidu.com/search/spider.htm)''baiduspider'0'0000-00-00 00:00:00''');
INSERT INTO `naps_stats_bot` VALUES (5'Yahoobot''Mozilla/5.0+(compatible;+Yahoo!+Slurp;+http://help.yahoo.com/help/us/ysearch/slurp)''slurp'0'0000-00-00 00:00:00''');
INSERT INTO `naps_stats_bot` VALUES (6'Sohubot''sohu-search''sohu-search'0'0000-00-00 00:00:00''');
INSERT INTO `naps_stats_bot` VALUES (7'Lycos''Lycos/x.x''lycos'0'0000-00-00 00:00:00''');
INSERT INTO `naps_stats_bot` VALUES (8'Robozilla''Robozilla/1.0''robozilla'0'0000-00-00 00:00:00''');

PHP程序如下:

以下为引用的内容:

<?php
/************************
* NAPS -- Network Article Publish System
* ----------------------------------------------
*     bot.php
*     -------------------
*  begin  : 2004-08-15
*
************************/
/************************
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; either version 2 of the License.
*
************************/
/************************
*
*  NAPS产品是自由软件。你可以且必须根据《GNU GPL-GNU通用公共许可证》的相关规定
*  复制、修改及分发NAPS产品。任何以NAPS产品为基础的衍生发行版未必须经过飘飘的授权。
*
************************/
error_reporting(E_ALL & ~E_NOTICE);
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;
}
$tlc_thispage addslashes($_SERVER['HTTP_USER_AGENT']);
//添加蜘蛛的抓取记录
$searchbot get_naps_bot();
if ($searchbot) {
 $DB_naps->query("UPDATE naps_stats_bot SET botcount=botcount+1, botlast=NOW(), botlasturl='$tlc_thispage' WHERE botname='$searchbot'");
}
?>

感谢各位的阅读!关于“PHP如何记录搜索引擎蜘蛛访问网站足迹”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI

开发者交流群×