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, it involves creating databases and recording various common search engine access methods in php. For more information, see the following example. 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' ('botid'), 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 (+ http://www.googlebot.com/bot.html ) ', 'Googlebot', 0, '2014-00-00 00:00:00 ', ''); insert into 'Naps _ stats_bot' VALUES (2, 'msnbot ', 'msnbot/0.1 ( http://search.msn.com/msnbot.htm ) ', 'Msnbot', 0, '2014-00-00 00:00:00 ', ''); insert into 'Naps _ stats_bot' VALUES (3, 'inktomi slurp ', 'slurp/100', 'slup', 0, '2017-00-00 00:00:00 ', ''); insert into 'Naps _ stats_bot' VALUES (4, 'baidider Ider ', 'baidider + (+ http://www.baidu.com/search/spider.htm ) ', 'Baidider', 0, '2014-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 ) ', '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 vers Ion 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.