SoFunction
Updated on 2025-03-06

How to record search engine spiders access website footprints

This article describes the method of PHP recording search engine spiders accessing website footprints. Share it for your reference. The specific analysis is as follows:

Search engine spiders visit websites by remotely crawling pages. We cannot use JS code to obtain spider agent information, but we can use image tags so that we can get spider agent information. Through the analysis of agent data, we can determine the type, gender and other factors of the spider. We can record it through database or text to conduct statistics.

Database structure:

The following is the quoted content:

#
# Table structure `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 ;
#
# Export data from table `naps_stats_bot`#
INSERT INTO `naps_stats_bot` VALUES (1, 'Googlebot', 'Googlebot/ (+/)', 'googlebot', 0, '0000-00-00 00:00:00', '');
INSERT INTO `naps_stats_bot` VALUES (2, 'MSNbot', 'MSNBOT/0.1 (/)', '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+(+/search/)', 'baiduspider', 0, '0000-00-00 00:00:00', '');
INSERT INTO `naps_stats_bot` VALUES (5, 'Yahoobot', 'Mozilla/5.0+(compatible;+Yahoo!+Slurp;+/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/', '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', '');

The PHP program is as follows:

The following is the quoted content:

<?php
/************************
* NAPS -- Network Article Publish System
* ----------------------------------------------
*     
*     -------------------
*  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 products are free software.  You can and must comply with the relevant provisions of the GNU GPL-GNU General Public License
 * Copy, modify and distribute NAPS products.  Any derivative distribution based on NAPS products does not have to be authorized by Piaopiao.
 *
 *********************************/
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']);
//Add spider's crawling record$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'");
}
?>

I hope this article will be helpful to everyone's PHP programming.