4k views
How to detect if a page is visited by a bot
Using the HTTP_USER_AGENT, it is possible to know if your page is visited by a bot. This is useful if you don't want to count these visits in your visits counter:
PHP
- protected function isBot()
- {
- /* This function will check whether the visitor is a search engine robot */
- "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
- "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
- "crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
- "msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
- "Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
- "Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
- "Butterfly","Twitturls","Me.dium","Twiceler");
- foreach($bots as $bot)
- {
- return true;
- }
- return false;
- }
Submitted by miguelSantirso over 2 years ago — last modified less than a minute ago