2

I just ran some random tests on my code and was shocked to discover that get_browser() read Opera as Google Chrome.

A few months ago get_browser() gave me correct results on all 5 browsers (chrome,ie,ff,opera,safari).

Today Opera displayed the same values with Google Chrome. First I thought get_browser() must be the problem so I tried getting alternatives. I saw this javascript alternative which works BUT like get_browser it also detected Opera as Google Chrome.

I made a quick search on this and found articles of Opera now using Chromium for its Desktop Browser.

Is that why my code is giving Opera and Google Chrome the same values?

I store user information for better user experience and it looks bad when my users are being told the wrong information.

Any ideas on how to keep individuality between Google Chrome and Opera?

All I can think of is using the user-agent but it can be faked.

Community
  • 1
  • 1
Jo E.
  • 6,278
  • 11
  • 44
  • 79

1 Answers1

2

Opera is now using Chromium/Blink as its basis. In order to solve compatibility issues, they purposely use Chrome's user-agent. Below is an example of UA string presented by Opera:

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

However, differentiation of Opera and Chrome is still possible as Opera appends its version to the user-agent as you can see above.

If you want to keep using get_browser() function of PHP, you should wait for a later release of PHP that implements detection of Opera natively. However, you can also write a function to do that job. In fact, get_browser() works by decoding the user-agent field of the headers of a HTTP request.

Isaac Kwan
  • 99
  • 2
  • 10
  • Yeah I saw the difference between the user agents earlier, as a quick alternative I used `strpos` to detect `OPR` from the `UA`. That's the only alternative I can think of for now. Was hoping for a different approach on this though. +1 for the link – Jo E. Aug 05 '13 at 16:29