PHP Method for recording the website footprint of search engine spider access, search engine footprint

Source: Internet
Author: User

PHP Method for recording the website footprint of search engine spider access, search engine footprint

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 (+ http://www.googlebot.com/bot.html )', 'bot bot ', 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, '2017-00-00 00:00:00 ', ''); insert into 'naps _ st Ats_bot 'values (3, 'inktomi slurp', 'slurp/123456', 'slurp', 0, '2017-00-00 00:00:00 ',''); insert into 'naps _ stats_bot 'VALUES (4, 'baidider ider', 'baidider ider + (+ http://www.baidu.com/search/spider.htm) ', 'baidider ider', 0, '2017-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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.