Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to count known bot useragents on differant total to nomal users?
Old 01-10-2008, 02:41 PM How to count known bot useragents on differant total to nomal users?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
hey,

I have a PHP counter script i made which basically saves ip, datetime and useragent to database and if that ip HASNT visited the site for a minimum of 24 hours adds 1 to the counter.

I have LOTS of yahoo slurp hits everyday and it messin up the counter so i want to be able to have a list (or array) of bots i want NOT to be counted and instead want it inserted a sep thing.

anyway im really not with it today so how woul do if(useragent == LIST_OF_BOTS_USERAGENTs) { add to bot total } else { add to normal total?

thanks.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 01-10-2008, 02:49 PM Re: How to count known bot useragents on differant total to nomal users?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
If you used ASP.NET, it would be if(noCountList.Contains(userAgent)) { ; } else { ; }. If PHP is a decent language like everyone says, you can do the same thing with slightly different syntax. If not, you can make a for loop to run through every item in the array until you find a match or hit the end. That's slow, but if you only have a few in the list it won't matter so much.

You might be better off counting hits from known browsers and excluding everything else? You could use a Regular Expression so as not to have to hard code every different version, but that protects you when Yahoo renames their bot, or Joe Blow makes one and runs it on your site.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 01-10-2008, 05:03 PM Re: How to count known bot useragents on differant total to nomal users?
The PHP Professor

Posts: 340
Name: Alex
Location: Behind You
Trades: 0
I was actually researching this a couple days ago. You can set your code like this:

NOTE: i don't actually know what the names of the bots are so i improvised


PHP Code:
<?php

// define your array
$bot_list = array ( 'YAHOO''GOOGLE''ASK''ALEXA' );

// get the user agent
$user_agent $_SERVER['HTTP_USER_AGENT'];

foreach ( 
$bot_list AS $bot_list 

    if ( 
strstr $user_agent$bot_list ) )
    {
        
// a bot is on the site!
    
}
}

?>
__________________
Go Kirby! <(" . "<) (^" . "^) (>" . ")> Talkupation!
microcolt is offline
Reply With Quote
View Public Profile Visit microcolt's homepage!
 
Old 01-10-2008, 10:00 PM Re: How to count known bot useragents on differant total to nomal users?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Here is a block of spider detection code I got from an adaptation from zencart. The session start if the spider flag is set true is only an option.

PHP Code:
<?php
  
  $user_agent 
strtolower($_SERVER['HTTP_USER_AGENT']);
  
$spider_flag false;
  
   if (!empty(
$user_agent))
   {
     
$spiders file('spiders.txt');
     for (
$i 0$i count($spiders); $i++)
     {
       if (!empty(
$spiders[$i]))
       {
         if (
is_integer(strpos($user_agenttrim($spiders[$i]))))
         {
           
$spider_flag true;
           break;
         }
       }
     }
   }
   
   if (
$spider_flag === false)
   {
     
session_start();
     
$session_started true;
   }
  
?>
spiders.txt
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-11-2008, 03:02 AM Re: How to count known bot useragents on differant total to nomal users?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Thanks Mgraphic that looks like the best way i will have yo get this when im at home (god knows why im at school at 8am but hey im not walking in this weather *holds ears because of noise of heavy rain on roof*)

thanks as well microcolt
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 01-11-2008, 12:09 PM Re: How to count known bot useragents on differant total to nomal users?
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
okay one question, how do i do the thing with php to send dif headers?

i want to just make a quick testing script which has a text field and a select field, select has all the dif useragents and bots and the text for a url so i can jsut access that site/page and pretend to be something else for testing?

Thansk
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to How to count known bot useragents on differant total to nomal users?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.43911 seconds with 13 queries