EllisLab/CodeIgniter — Issue #604: wrong detected user agent - googlebot,yahoo
Author: FDiskas
Created: 2011-10-20 22:06:51+00:00
State: open

Using firefox plugin I changed my user agent sring to:

Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

User agent string was taken from: http://www.useragentstring.com/pages/Googlebot/

In controller I used code provided in documentation: http://codeigniter.com/user_guide/libraries/user_agent.html

```PHP
$this->load->library('user_agent');

if ($this->agent->is_browser())
{
$agent = $this->agent->browser().' '.$this->agent->version();
}
elseif ($this->agent->is_robot())
{
$agent = $this->agent->robot();
}
elseif ($this->agent->is_mobile())
{
$agent = $this->agent->mobile();
}
else
{
$agent = 'Unidentified User Agent';
}

echo $agent;

echo $this->agent->platform(); // Platform info (Windows, Linux, Mac, etc.)
```

Result:

Mozilla 5.0Unknown Platform

That is wrong. Must be:

GooglebotUnknown Platform

To fix that bug I reordered a detectetion priority in array. First check if this is a robot then ather.

```PATCH
Index: system/libraries/User_agent.php
===================================================================
--- system/libraries/User_agent.php	(revision )
+++ system/libraries/User_agent.php	(revision )
@@ -142,7 +142,7 @@
{
$this->_set_platform();

-	foreach (array('_set_browser', '_set_robot', '_set_mobile') as $function)
+	foreach (array('_set_robot', '_set_browser', '_set_mobile') as $function)
{
if ($this->$function() === TRUE)
{
```

Now bots are detected but wrong type of bot.
Eemple - yahoo user agent is:

Mozilla/5.0 (compatible; Yahoo! Slurp; http://help.yahoo.com/help/us/ysearch/slurp)

Helper results are:

Inktomi SlurpUnknown Platform

Must be:

YahooUnknown Platform

In order to fix that i changed ordering in config/user_agents.php

```PATCH
Index: application/config/user_agents.php
===================================================================
--- application/config/user_agents.php	(revision )
+++ application/config/user_agents.php	(revision )
@@ -166,8 +166,8 @@
$robots = array(
'googlebot'	=> 'Googlebot',
'msnbot'	=> 'MSNBot',
-	'slurp'	=> 'Inktomi Slurp',
'yahoo'	=> 'Yahoo',
+	'slurp'	=> 'Inktomi Slurp',
'askjeeves'	=> 'AskJeeves',
'fastcrawler'	=> 'FastCrawler',
'infoseek'	=> 'InfoSeek Robot 1.0',

```