This article describes how to record the website footprint of a search engine spider in PHP. The example shows how to record the Web footprint of a search engine spider in php, database creation and php recording of various common search engine access
This article describes how to record the website footprint of a search engine spider in PHP. The example shows how to record the Web footprint of a search engine spider in php, database creation and php recording of various common search engine access
This example describes how to record the website footprint of a search engine spider in PHP. Share it with you for your reference. The specific analysis is as follows:
The search engine crawlers access websites by capturing pages remotely. We cannot use JS Code to obtain the Agent information of the spider, but we can use the image Tag ,, in this way, we can obtain the agent data of the Spider. By analyzing the agent data, we can determine the types, gender, and other factors of the spider, we can record statistics through databases or text.
Database Structure:
Reference content is as follows:
# 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 '2017-00-00 00:00:00 ', 'botlasturl' varchar (0000) not null default '', unique key 'botid' ('bo Tid'), KEY 'botname' ('botname') TYPE = MyISAM AUTO_INCREMENT = 9; # export data in the table 'naps _ stats_bot '# insert into 'naps _ stats_bot' VALUES (1, 'googlebot ', 'googlebot/2.X (+)', 'googlebot ', 0, '2014-00-00 00:00:00 ', ''); insert into 'naps _ stats_bot' VALUES (2, 'msnbot ', 'msnbot/0000 ()', 'msnbot ', 0, '2014-00-00 00:00:00', ''); insert into 'naps _ stats_bot 'VALUES (3, 'inktomi slurp ', 'slurp/100', 'slurp', 0, '00 00-00-00 00:00:00 ', ''); insert into 'naps _ stats_bot' VALUES (4, 'baidider ider ', 'baidider ider + (+)', 'baidider ider ', 0, '2014-00-00 00:00:00 ', ''); insert into 'naps _ stats_bot' VALUES (5, 'yahoobot ', 'mozilla/0000 + (compatible; + Yahoo! + Slurp; +) ', 'slup', 0, '2017-00-00 00:00:00', ''); insert into 'naps _ stats_bot 'VALUES (6, 'sohubot ', 'sohu-search', 'sohu-search', 0, '2017-00-00 00:00:00 ',''); insert into 'naps _ stats_bot 'VALUES (7, 'lycos', 'lycos/x. x', 'lycos ', 0, '2014-00-00 00:00:00', ''); insert into 'naps _ stats_bot 'VALUES (8, 'robozilla ', 'robozilla/123456', 'robozilla ', 0, '2017-00-00 00:00:00 ','');
The PHP program is as follows:
Reference content is as follows:
<? Php/************************ NAPS -- Network Article Publish System ** ------------------------------------------------------ * bot. php * ------------------- * begin: *************************//************ * ************* 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 versio N 2 of the License. *************************//************* * ************ NAPS products are free software. You may and must copy, modify and distribute NAPS in accordance with the GNU GPL-GNU General Public License. Any derivative release based on NAPS product is not subject to authorization. * ***********************/Error_reporting (E_ALL &~ E_NOTICE); function get_naps_bot () {$ useragent = strtolower ($ _ SERVER ['HTTP _ USER_AGENT ']); if (strpos ($ useragent, 'googlebot ')! = False) {return 'bot bot ';} if (strpos ($ useragent, 'msnbot ')! = False) {return 'msnbot ';} if (strpos ($ useragent, 'slurp ')! = False) {return 'yahoobot ';} if (strpos ($ useragent, 'baidider ider ')! = False) {return 'baidider ider ';} 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 the crawler capture 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 help you with php programming.