Welcome Guest, Not a member yet? Register   Sign In
UPDATE to the new 2.03 user agent class
#1

[eluser]salfordscripteR[/eluser]
After playing with the user agent code it became apparent that Repeating the following code each time you wanted a nice neat browser name got a little messy:
Code:
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;

So to fix this isue i simply put it at the bottom of the user agent class as follows:
(ROOT/system/libraries/User_agent.php)
Code:
/**
* Is real Browser
*
* @access public
* @return bool
*/
public function is_Real_browser($key = NULL)
{
  if ($this->is_browser())
  {
      $agent = $this->browser().' '.$this->version();
  }
  elseif ($this->is_robot())
  {
      $agent = $this->robot();
  }
  elseif ($this->is_mobile())
  {
      $agent = $this->mobile();
  }
  else
  {
      $agent = 'Uknown';
  }

  return $agent;
}


The to call it simple use:
Code:
$this->agent->is_Real_browser();

Hope this helps, maby it could be added to the SVN




Theme © iAndrew 2016 - Forum software by © MyBB