Search engine spiders visit the site through the remote crawl page to do, we can not use the JS code to obtain the spider agent information, but we can through the image tag, so we can get the spider agent data, through the agent data analysis, you can determine the type of spider , gender and other factors, we can be recorded through the database or text to be counted.
Database structure:
#
# The structure of the table ' Naps_stats_bot '
#
CREATE TABLE ' Naps_stats_bot ' (
' Botid ' int (a) unsigned not NULL auto_increment,
' botname ' varchar not NULL default ',
' botagent ' varchar not NULL default ',
' Bottag ' varchar not NULL default ',
' Botcount ' int (one) not NULL default ' 0 ',
' Botlast ' datetime not NULL default ' 0000-00-00 00:00:00 ',
' Botlasturl ' varchar not NULL default ',
UNIQUE KEY ' Botid ' (' Botid '),
KEY ' Botname ' (' Botname ')
) Type=myisam auto_increment=9;
#
# Export the 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, ' 0000-00-00 00:00:00 ', ');
INSERT into ' Naps_stats_bot ' VALUES (2, ' msnbot ', ' msnbot/0.1 (http://search.msn.com/msnbot.htm) ', ' 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 (http://www.baidu.com/search/spider.htm) ', ' Baiduspider ', 0, ' 0000-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, ' 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/x.x ', ' 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 ');
PHP Program:
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 Crawl 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 ');
}
?>