PHP记录搜索引擎蜘蛛访问网站足迹的方法

 更新时间:2015年04月15日 11:21:09   作者:php118  
这篇文章主要介绍了PHP记录搜索引擎蜘蛛访问网站足迹的方法,实例分析了针对php记录搜索引擎蜘蛛访问足迹的技巧,涉及数据库的创建及php记录各类常见搜索引擎访问的方法,需要的朋友可以参考下

本文实例讲述了PHP记录搜索引擎蜘蛛访问网站足迹的方法。分享给大家供大家参考。具体分析如下:

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

数据库结构:

以下为引用的内容:

#
# 表的结构 `naps_stats_bot`
#

CREATE TABLE `naps_stats_bot` (
`botid` int(10) unsigned NOT NULL auto_increment,
`botname` varchar(100) NOT NULL default '',
`botagent` varchar(200) NOT NULL default '',
`bottag` varchar(100) NOT NULL default '',
`botcount` int(11) NOT NULL default '0',
`botlast` datetime NOT NULL default '0000-00-00 00:00:00',
`botlasturl` varchar(250) NOT 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程序设计有所帮助。

相关文章

  • PHP如何实现Unicode和Utf-8编码相互转换

    PHP如何实现Unicode和Utf-8编码相互转换

    本文介绍了通过PHP实现一个函数可以对字符串进行Unicode的编码和解码,需要的朋友可以参考下
    2015-07-07
  • php数组去重的函数代码

    php数组去重的函数代码

    php中数组去重的小例子,供初学者参考
    2013-02-02
  • php获取网卡的MAC地址支持WIN/LINUX系统

    php获取网卡的MAC地址支持WIN/LINUX系统

    这篇文章主要介绍了使用php获取网卡的MAC地址支持WIN/LINUX系统,需要的朋友可以参考下
    2014-04-04
  • php好代码风格的阶段性总结

    php好代码风格的阶段性总结

    这篇文章主要介绍了php好代码风格,阶段性总结了php程序设计中变量、函数、参数的相关使用注意事项与编程技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2016-06-06
  • 完美解决thinkphp唯一索引重复时出错的问题

    完美解决thinkphp唯一索引重复时出错的问题

    下面小编就为大家带来一篇完美解决thinkphp唯一索引重复时出错的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-03-03
  • PHP实现的简单适配器模式示例

    PHP实现的简单适配器模式示例

    这篇文章主要介绍了PHP实现的简单适配器模式,结合具体实例形式分析了php适配器模式的实现技巧与调用方法,需要的朋友可以参考下
    2017-06-06
  • php利用iframe实现无刷新文件上传功能的代码

    php利用iframe实现无刷新文件上传功能的代码

    上传原理很简单就是利用表单的打开方式为iframe的id名,这样就可以在当前页面的iframe打来了,实现文件上传,再利用js返回上传结果。
    2011-09-09
  • PHP结构型模式之装饰器模式

    PHP结构型模式之装饰器模式

    这篇文章主要介绍了PHP结构型模式之装饰器模式,装饰器模式是一种结构型模式,它允许你在运行时为一个对象动态地添加新的行为,而不影响其原始的行为。这种类型的设计模式属于结构型模式,它结合了透明性和多样性
    2023-04-04
  • PHP调用Twitter的RSS的实现代码

    PHP调用Twitter的RSS的实现代码

    “守望轩”博客右侧边栏原来有个“杂感”的栏目,用来记录短的、不能大篇幅成文的短句,或者自己比较喜欢的短句和言论。
    2010-03-03
  • php 强制下载文件实现代码

    php 强制下载文件实现代码

    php 强制下载文件实现代码。需要的朋友可以过来参考下,希望对大家有所帮助
    2013-10-10

最新评论