PHP記錄搜索引擎蜘蛛訪問網(wǎng)站足跡的方法
本文實(shí)例講述了PHP記錄搜索引擎蜘蛛訪問網(wǎng)站足跡的方法。分享給大家供大家參考。具體分析如下:
搜索引擎的蜘蛛訪問網(wǎng)站是通過遠(yuǎn)程抓取頁面來進(jìn)行的,我們不能使用JS代碼來取得蜘蛛的Agent信息,但是我們可以通過image標(biāo)簽,這樣我們就可以得到蜘蛛的agent資料了,通過對(duì)agent資料的分析,就可以確定蜘蛛的種類、性別等因素,我們?cè)谕ㄟ^數(shù)據(jù)庫或者文本來記錄就可以進(jìn)行統(tǒng)計(jì)了。
數(shù)據(jù)庫結(jié)構(gòu):
以下為引用的內(nèi)容:
# # 表的結(jié)構(gòu) `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 ; # # 導(dǎo)出表中的數(shù)據(jù) `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程序如下:
以下為引用的內(nèi)容:
<?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產(chǎn)品是自由軟件。你可以且必須根據(jù)《GNU GPL-GNU通用公共許可證》的相關(guān)規(guī)定
* 復(fù)制、修改及分發(fā)NAPS產(chǎn)品。任何以NAPS產(chǎn)品為基礎(chǔ)的衍生發(fā)行版未必須經(jīng)過飄飄的授權(quán)。
*
************************/
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'");
}
?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
相關(guān)文章
PHP如何實(shí)現(xiàn)Unicode和Utf-8編碼相互轉(zhuǎn)換
本文介紹了通過PHP實(shí)現(xiàn)一個(gè)函數(shù)可以對(duì)字符串進(jìn)行Unicode的編碼和解碼,需要的朋友可以參考下2015-07-07
php獲取網(wǎng)卡的MAC地址支持WIN/LINUX系統(tǒng)
這篇文章主要介紹了使用php獲取網(wǎng)卡的MAC地址支持WIN/LINUX系統(tǒng),需要的朋友可以參考下2014-04-04
完美解決thinkphp唯一索引重復(fù)時(shí)出錯(cuò)的問題
下面小編就為大家?guī)硪黄昝澜鉀Qthinkphp唯一索引重復(fù)時(shí)出錯(cuò)的問題。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03
php利用iframe實(shí)現(xiàn)無刷新文件上傳功能的代碼
上傳原理很簡單就是利用表單的打開方式為iframe的id名,這樣就可以在當(dāng)前頁面的iframe打來了,實(shí)現(xiàn)文件上傳,再利用js返回上傳結(jié)果。2011-09-09
PHP調(diào)用Twitter的RSS的實(shí)現(xiàn)代碼
“守望軒”博客右側(cè)邊欄原來有個(gè)“雜感”的欄目,用來記錄短的、不能大篇幅成文的短句,或者自己比較喜歡的短句和言論。2010-03-03
php 強(qiáng)制下載文件實(shí)現(xiàn)代碼
php 強(qiáng)制下載文件實(shí)現(xiàn)代碼。需要的朋友可以過來參考下,希望對(duì)大家有所幫助2013-10-10

