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
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
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
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
Share on other sites

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...

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.