Language identification (Opera, Safari, Chrome) in PHP
I'm using $_SERVER["HTTP_ACCEPT_LANGUAGE"]
to detect the browser language, which works fine for Firefox and IE:
Firefox:
de,en-us;q=0.9,en;q=0.7,ru;q=0.6,ro;q=0.4,hu;q=0.3,zh;q=0.1
Internet Explorer:
de
Unfortunately, it doesn't work for the following browsers:
Opera:
en,en-US;q=0.9,ja;q=0.8,fr;q=0.7,de;q=0.6,es;q=0.5,it;q=0.4,pt;q=0.3,pt-PT;q=0.2,nl;q=0.1,sv;q=0.1,nb;q=0.1,da;q=0.1,fi;q=0.1,ru;q=0.1,pl;q=0.1,zh-CN;q=0.1,zh-TW;q=0.1,ko;q=0.1
Safari:
en-us
Chrome:
en-US,en;q=0.8
I don't see any fields in the phpinfo
output which would be helpful. P开发者_如何转开发lease let me know if you have any suggestions. Many thanks!
I don't have all those browsers, but what about $_SERVER["HTTP_USER_AGENT"]
?
Firefox:
Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8
Chromium:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.470.0 Safari/534.3
In my case that's normal because I'm using chromium with en-US and Firefox with it (Italian)
I don't quite understand what doesn't "work" for you here. All browsers send relatively sensible and syntactically correct Accept-Language headers. Opera most likely sends what it is configured to send in "Preferences > General > Language > Details". If you want your Opera to request a different language or prioritise them differently, this is where you go to change it.
精彩评论