banner counter doesn't work correctly

Discussion in 'MySQL' started by leofire, Dec 17, 2012.

  1. #1
    Hi to all,

    I'm in trouble, I wrote a PHP script in order to store in a Database how many times the banner are viewed in particular the query that make the update is:
    $queryUpdBanner = "UPDATE $nomeTabBannerAziende SET visualizzazioni = visualizzazioni + 1 WHERE key_bnr = '$idBanner' LIMIT 1";
    $sqlUpdBanner = @mysql_query($queryUpdBanner);

    key_bnr is an autoincrement primary key of that table.
    This query is not in a while or for cycle. All my script for all format work in this manner:
    - for this specific format
    - for every banner that I can find
    - based by probability (from 1 to 5) put the id of this banner into an array (if probability is 1 put just 1 id, otherwise put the same id 1,2,3,4 or 5 times into that array).
    - select a random number from 1 to number of the element into this array
    - select that specific id and extract the specific banner (JPG,GIF,SWF,PNG, HTML)
    - increase the views for thi specific id.

    Into stage area where I'm alone, if I try with three different curl (for($i=1;$i<301;$i++)) the banner will be counted correctly but into the live site it does not in particular, from Google Analytics I have this result:
    Visits: 13,363
    Unique Visitors: 12,005
    Pageviews: 36,414

    Into my table, for a specific format (300x250) I have:
    visualizzazioni: 94.031

    I have searched the name of the table in all php script and it's appear only in my php script for every format (ads_300x250.php, ads_728x90.php ads_300x250_2.php and so on) and in every script I set the format in my head section in order to select only the banner for that specific format (300x250, 728x90, 300x250_2 and so on).

    In order to understand what happened I have also removed that banner from the 404 page and the standard page that I use for system message.

    I have also counted the unique ip addresses into my log file with:
    cat logfile.log | grep "16/Dec/2012" | awk '{print $1}' | sort | uniq -c

    it show me 12.883

    I still monitoring the situation but I don't know where I wrong :confused:
    Can anyone help me ?
    Thanks in advance to everybody,


    Leo
     
    leofire, Dec 17, 2012 IP
  2. PYO

    PYO Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    Try awstats for log analyzing. The problem is obvious: there are many bots/spiders that your scripts counts also.
     
    PYO, Dec 18, 2012 IP
  3. leofire

    leofire Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi PYO, thanks for your reply but is not so easy...

    Into my script I block for spider with this part:
    ...
    if ( ! function_exists('getIsCrawler'))
    {
    function getIsCrawler($userAgent) {
    $crawlers = 'Google|msnbot|Rambler|Yahoo|AbachoBOT|accoona|AcioRobot|ASPSeek|CocoCrawler|Dumbot|FAST-WebCrawler|GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby|proximic|bingbot|sistrix|Yandex';
    $isCrawler = (preg_match("/$crawlers/i", $userAgent) > 0);
    return $isCrawler;
    }
    }

    $iscrawler = getIsCrawler($_SERVER['HTTP_USER_AGENT']);

    if (!($iscrawler))
    {
    $queryUpdBanner = "UPDATE $nomeTabBannerAziende SET visualizzazioni = visualizzazioni + 1 WHERE key_bnr = '$idBanner' LIMIT 1";
    $sqlUpdBanner = @mysql_query($queryUpdBanner);
    }
    ...

    but the result is not correct, for example:
    19-12-12 (24h)
    Impression delivered: 66.449

    Analytics stats:
    Visits: 13.399
    Unique Visitors: 12.005
    Pageviews: 35.374

    Is this incorrect ? :confused:

    What could go wrong ?
    Thanks for your support,


    Leonardo
     
    leofire, Dec 19, 2012 IP
  4. PYO

    PYO Member

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    Leonardo,

    please read my previous comment carefully. With such code you still count hits, but not visitors (yes, you are not counting hits from Google|msnbot|Rambler|Yahoo|AbachoBOT|accoona|AcioRobot|ASPSeek|CocoCrawler|Dumbot|FAST-WebCrawler|GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby|proximic|bingbot|sistrix|Yandex).
    1) This list is outdated and far from being complete.
    2) This code will count hit from bot with user agent
    Mozilla/5.0 (compatible; Baiduspider/2.0; +http://www.baidu.com/search/spider.html)
    or
    Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.9.168 Version/11.51
     
    PYO, Dec 19, 2012 IP
  5. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #5
    If I'm understanding you, you can't update an autoincrement field. It autoincrements on every insert (so each record has a unique value for that field). It's used as an ID field, not a counting field. (Consider it a read-only field.)
     
    Rukbat, Dec 20, 2012 IP
  6. leofire

    leofire Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi PYO,

    thanks for your suggestion! I have update the list and now everything works fine!
    This is my bot&spider list:
    $crawlers = 'Google|msnbot|Rambler|Yahoo|AbachoBOT|accoona|AcioRobot|ASPSeek|CocoCrawler|Dumbot|FAST-WebCrawler|GeonaBot|Gigabot|Lycos|MSRBOT|Scooter|AltaVista|IDBot|eStyle|Scrubby|proximic|bingbot|sistrix|Yandex|Baidu|Presto|Jike|Yodao|Ahrefs|WebZIP|Sosospider|OpenindexSpider|Exabot|UptimeRobot|ezooms|MJ12bot|Phantom| AcoonBot|WBSearchBot|CareerBot|Yeti|Girafabot|psbot|TurnitinBot|4SeoHuntBot|Mail.RU_Bot';


    Many thanks and good christmas,


    Leonardo:D
     
    leofire, Dec 22, 2012 IP