本文实例讲述了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程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!