code is not finding all 'bots' !

This is a discussion on "code is not finding all 'bots' !" within the PHP Forum section. This forum, and the thread "code is not finding all 'bots' ! are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Dec 2nd, 2006, 23:44
Junior Member
Join Date: Dec 2006
Location: uk
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
code is not finding all 'bots' !

I have this code that was give to me a while ago, but it seems now that it does not get the bots!

the bots array has a list of text that in contained within the HTTP_USER_AGENT
i have created my own counter so i can have a relistic figure showing how many actually people have viewed the site.

what i would like someone do kindly do for me is check this code and tell me how i should change it so it checks for any case (upper or lower) that may be in the $subject variable.

I was told that the "/" and "/i" are what does this but i am sure it is not working for me as i am still getting some bots get throught and increasing my counter.

thank you in advance for your help.

J


Code: Select all
    $subject = $_SERVER['HTTP_USER_AGENT'];
    $num_bots=0;
    $bots = array("spider","bot.htm","crawl","slurp","msnbot");
    foreach($bots as $num=>$bot){
    preg_match("/".$bot."/i", $subject, $matches);
        if(count($matches) >0){
        //Found a match! DO NOT INCREASE
        $addone = mysql_query("UPDATE counters SET value = value+1 WHERE field = 'webbot'");
        $num_bots++;
        }else{
            //no bot.
            }
    }

Last edited by Jason3107; Dec 2nd, 2006 at 23:48.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Dec 3rd, 2006, 17:52
Reputable Member
Join Date: Jul 2005
Location: Melksham, Wilts, UK
Posts: 293
Thanks: 0
Thanked 0 Times in 0 Posts
Re: code is not finding all 'bots' !

Jason, each of the bots decides on its own user agent string, and so at best you'll catch most of them. By carefully filtering your log files and changing the strings you look for, you may improve the filters, but there's no fail-safe solution by eliminating.

Two alternatives that may work for you / assist you

1. Look and see what / who has read your robots.txt file, and use that as a basis / additional basis for for identifying bots

2. Instead of a blacklist principle, a white list principle may work better for you - look for visits from known human visitors and count that way, perhaps?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
case insesitive search

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
stopping bots saltedm8 Webforumz Cafe 14 Dec 13th, 2007 00:20
pesky Search Engine bots eon201 Search Engine Optimization (SEO) 0 Nov 9th, 2007 10:32
Google Bots Pádraig Search Engine Optimization (SEO) 5 Jun 29th, 2007 23:09
Guestbook Spam Bots v Human Help.. Andy_H Classic ASP 9 Jan 29th, 2006 13:48


All times are GMT. The time now is 10:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved