andy222
andy222

Reputation: 125

Codeigniter User Agent detect Opera browser as Chrome

I'm trying to show the browser that I used to open my site using Codeigniter User Agent Libraries. When I open with IE,Chrome,Firefox,and Safari, User agent return the right value. But when I open with Opera, it return "Chrome" value.

here is part of my code:

Controller

*** another code ***

$this->load->library('user_agent');
$data['browser'] = $this->agent->browser();
$this->load->view('agent',$data);

*** another code ***

View

Your browser is <span><?php echo $browser; ?></span>.

the result if I open with opera is this:

Your browser is Chrome.

My question is, why it return Chrome? How can I fix this problem?

Thanks.

Upvotes: 3

Views: 1626

Answers (1)

Drew
Drew

Reputation: 3234

It looks like the user agent string in opera (since version 15) is this:

Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.100

You might need to extend the user_agent library to do a check to see if the user agent string contains OPR.

https://dev.opera.com/blog/opera-user-agent-strings-opera-15-and-beyond/

Upvotes: 1

Related Questions