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
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.
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:
Well, I probably did not use the right term, but the code posted by superdav42 was actually what I was looking for. Thanks!
Are you just asking in general or are you currently using a specific software tracker and need to make this modification?
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.)
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
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.
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.