Search

Rss Posts

Rss Comments

Login

 

Posts from January, 2009

How to define search engine bot on website (using PHP)?

Jan 27

Add to root folder of websitefile  bot.php

<?
if (strstr($_SERVER['HTTP_USER_AGENT'], 'Yandex')){ $bot='Yandex';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Googlebot')){$bot='Google';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Mediapartners-Google')){$bot='Mediapartners-Google (Adsense)';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Slurp')){$bot='Hot&nbsp;Bot&nbsp;search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'WebCrawler')){$bot='WebCrawler&nbsp;search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'ZyBorg')){$bot='Wisenut&nbsp;search';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'scooter')){$bot='AltaVista';}  
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'StackRambler')){$bot='Rambler';}  
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'Aport')){$bot='Aport';}  
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'lycos')){$bot='Lycos';}  
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'WebAlta')){$bot='WebAlta';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'yahoo')){$bot='Yahoo';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'msnbot')){$bot='msnbot/1.0';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'ia_archiver')){$bot='Alexa search engine';}
else if (strstr($_SERVER['HTTP_USER_AGENT'], 'FAST')){$bot='AllTheWeb';}
 
if($bot !=""){
$b_data = "bots.txt";
$inf = date("YmdHis",time());
$day = date("d.m.Y",time());
$time = date("H:i",time());
$ip = $REMOTE_ADDR;
$home = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = fopen($b_data, "a");
fwrite($data, "$inf|$day|$time|$bot|$ip|$home|rn");
fclose($data);
}
?>

This code tracks visits to your site 15 different bots. Naturally, the list can be extended – is represented by no means all of the existing ones.

Use it, you can read: let’s say your site has a template, and its “assembly” used files header.php ( “cap” of the site) and footer.php ( “basement”). Typically, these files are inserted at the beginning and end of each page on your site.
To carried out statistics on the Hits In of SE bots in this case, you must add the file header.php following code:

include("bot.php");

Now all the bots will be tracked and kept locked in a file bots.txt on your server.
PS. Do not forget to change CHMOD of bots.txt to 777

 
Get Adobe Flash playerPlugin by wpburn.com wordpress themes
27 queries. 0.446 seconds.