Jump to content

Showing bots on site


SuperMario290

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-817077
Share on other sites

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.

 

Link to comment
https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-817080
Share on other sites

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/155300-showing-bots-on-site/#findComment-818012
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.