SuperMario290 Posted April 23, 2009 Share Posted April 23, 2009 Okay, so I was wondering if this code is correct for showing the bots (eg: googlebot, etc...) on a website, or if it is wrong in some way. If you have other code that is guaranteed to work, please post it. This is for a friend of mine, and I'm trying to help him out a little bit. <?php $bot_list = array("Inktomi Slurp", "Googlebot", "Scooter", "MSNBot", "Ahoy! The Homepage Finder", "The Jubii Indexing Robot", "AskJeeves", "AbachoBOT", "KIT Fireball"); function detect_bot() { global $bot_list; foreach($bot_list as $bot) { if(ereg($bot, $_SERVER['HTTP_USER_AGENT'])) { $thebot = $bot; } } if ($bot) { print " Bots visiting site now: $thebot"; } } ?> Thanks, SuperMario290 Quote Link to comment https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/ Share on other sites More sharing options...
schilly Posted April 23, 2009 Share Posted April 23, 2009 i don't think that will work. if you are loading that script in your browser the HTTP_USER_AGENT will be you and not the bot. might have to log each USER_AGENT in a db with a session_id maybe. then use session tracking to see if they are still viewing the site. then just display the db info to see which bots are currently indexing. Quote Link to comment https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-817077 Share on other sites More sharing options...
laffin Posted April 23, 2009 Share Posted April 23, 2009 But the code should work to initially detect the bot.... But I really like Schilly's idea of using a session to keep track of specific bots and ya can add in login time, last access time, as well as page visits for bots to give u a general idea of what they commonly visit and improve a page hit. Quote Link to comment https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-817080 Share on other sites More sharing options...
schilly Posted April 23, 2009 Share Posted April 23, 2009 well it will work for the bot when it loads the page but only the bot will see it. Quote Link to comment https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-817087 Share on other sites More sharing options...
SuperMario290 Posted April 23, 2009 Author Share Posted April 23, 2009 Does anyone have some code for this to work? I've tried a lot of things but nothing's working. Quote Link to comment https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-817919 Share on other sites More sharing options...
DarkSuperHero Posted April 24, 2009 Share Posted April 24, 2009 how about posting the information into a flat file, and reading/writing to it evertime the page is accessed...any data that is older than say 5 minutes is deleted....using the time() which would be the number of seconds since the beginning of the internet epoch eg flatfile: botName:visitedOn googleBot:1002326265626295635659 askJeevesBot:1002326265626295636556 //read using file(); which gets each line of file into an array element //iterate through elements and explode() them at separator...compare....if the bot that is accessing the file does not match one add an array element...else update the array's time then write the elements of your updated array into the textfile.... you would then echo which bots are currently online by looking at the flat file Quote Link to comment https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-818012 Share on other sites More sharing options...
laffin Posted April 24, 2009 Share Posted April 24, 2009 Why keep track of timeouts, when sessions already handle that. Question is do bots store cookies, as sessions require a cookie. if not you may need yer own unique session management system, and create the timeout/expired system into it as well... Quote Link to comment https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-818060 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.