1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

quick bot detection

Discussion in 'PHP' started by vlasta, Oct 12, 2009.

  1. #1
    Hi all,

    I would like to count pageviews, but obviously I do not want bots to inflate the number.

    I am looking for a one-line php code that would give me an educated guess about the visitor being a real person or a bot. 100% accuracy is NOT needed. I would prefer simplicity.

    Thanks in advance,
    Vlasta
     
    vlasta, Oct 12, 2009 IP
  2. WeedGrinch

    WeedGrinch Active Member

    Messages:
    1,236
    Likes Received:
    73
    Best Answers:
    0
    Trophy Points:
    90
    #2
    Kind of asking for an unreal task.
    What if I opened my browser and viewed your website?
    What if I made a bot to open my browser and view your website?
    How would you be able to tell?

    PHP can do cool things, but it isn't God.
     
    WeedGrinch, Oct 12, 2009 IP
  3. superdav42

    superdav42 Active Member

    Messages:
    125
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #3
    just look at the user agent for the common bots.

    
    $bot_list = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
    "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");
    
    
    foreach($botlist as $bot) {
    if(ereg($bot, $_SERVER['HTTP_USER_AGENT'])) {
    echo "We have a bot: " , $bot;
    }
    } 
    
    PHP:
     
    superdav42, Oct 12, 2009 IP
  4. WeedGrinch

    WeedGrinch Active Member

    Messages:
    1,236
    Likes Received:
    73
    Best Answers:
    0
    Trophy Points:
    90
    #4
    I thought he was referring to bots, as opposed to indexers/spiders.
     
    WeedGrinch, Oct 12, 2009 IP
  5. vlasta

    vlasta Peon

    Messages:
    173
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Well, I probably did not use the right term, but the code posted by superdav42 was actually what I was looking for. Thanks!
     
    vlasta, Oct 12, 2009 IP
  6. theapparatus

    theapparatus Peon

    Messages:
    2,925
    Likes Received:
    119
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Are you just asking in general or are you currently using a specific software tracker and need to make this modification?
     
    theapparatus, Oct 12, 2009 IP
  7. vlasta

    vlasta Peon

    Messages:
    173
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I am building my own rudimentary forum script and I needed this bit. (If you want to know why I do not use phpbb or something else readily available, it is because I have bad experience using established packages. They are easy target for spammers and hackers and do not integrate well with the rest of the site.)
     
    vlasta, Oct 12, 2009 IP
  8. astrazone

    astrazone Member

    Messages:
    358
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #8
    you can do daily views or hourly updated (each IP gets 1 view) and can get another one in 1hr.
    so max that bot can do is 24 per hour... I dont think that its going to effect much.
    consider that
     
    astrazone, Oct 12, 2009 IP
  9. goliath

    goliath Active Member

    Messages:
    308
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    60
    #9

    If an independently spidering page scraper isn't a bot, what is?
     
    goliath, Oct 13, 2009 IP
  10. WeedGrinch

    WeedGrinch Active Member

    Messages:
    1,236
    Likes Received:
    73
    Best Answers:
    0
    Trophy Points:
    90
    #10
    I didn't say an "independently spidering page scraper" wasn't a bot, I said that's not what I thought he meant. Smart ass.
     
    WeedGrinch, Oct 14, 2009 IP
  11. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Most bots don't have Javascript enabled. Using Javascript to weed out ~90% of them.

    Use a snippet of Javascript to call a PHP script.

    
    <script language="JavaScript" type="text/javascript">
      phpCounter = new Image();
      phpCounter.src = "http://domain.com/counter.php";
    </script>
    
    Code (markup):
    And the PHP file is just a basic counter.
     
    organicCyborg, Oct 14, 2009 IP