Count whether a spider accesses your website through the PHP program

Source: Internet
Author: User
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 type, gender, and other factors of the Spider. we can record the data through the database or text.

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:

#
# 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 (250) not null default '',
Unique key 'botid' ('botid '),
KEY 'botname' ('botname ')
) TYPE = MyISAM AUTO_INCREMENT = 9;

#
# Export the table data 'Naps _ stats_bot'
#

Insert into 'Naps _ stats_bot 'VALUES (1, 'googlebot', 'googlebot/2.X (http://www.googlebot.com/bot.html) ', 'googlebot', 0, '2017-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 _ stats_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) ', 'slurp', 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, '2017-00-00 00:00:00 ','');
Insert into 'Naps _ stats_bot 'VALUES (8, 'robozilla', 'robozilla/123456', 'robozilla ', 0, '2017-00-00 00:00:00 ','');

  PHP program:

/*************************************** ************************************
* NAPS -- Network Article Publish System
*----------------------------------------------
* Bot. php
*-------------------
* Begin: 2004-08-15
* Copyright: (C) 2004 week9
* Email: wapshow@gmail.com
* Homepage: http://www.week9.com
* Http://www.wapshow.com
*
**************************************** ***********************************/

/*************************************** ************************************
*
* This program is free software; you can redistribute it and/or modify
* It under the terms of the GNU General Public License as published
* The Free Software Foundation; either version 2 of the License.
*
**************************************** ***********************************/

/*************************************** ************************************
*
* NAPS products are free software. You can and must comply with the GNU GPL-GNU General Public License
* Copy, modify, and distribute NAPS. 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 a crawler 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 '");
}

?>

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.