我正在Linux中的本地Apache 2 Web服务器中编写一些网页,我想使用PHP来自动识别浏览器语言。
在网页中,我尝试console.log()
使用JavaScript,了解客户端首选的语言,并获得2种不同的输出:
console.log(navigator.language);
)返回es-ES
<?php echo $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?>
)返回en-US,en;q=0.5
在about:config
中,变量intl.accept_languages
设置为es-ES, es, en-US, en
。
注意:我想要获得的当地语言是西班牙语(es-ES
)。
出于任何原因,我的Linux发行版(Linux Mint 18.1)中似乎没有正确配置Firefox,而我安装了所有内容(firefox
和firefox-locale-es
)。
如果我在同一台计算机上使用Chromium,PHP输出为es-ES,es;q=0.8;q=0.6
,这是正确的。
如果我在其他使用Windows的计算机上使用Firefox,或者甚至使用适用于Android的Firefox,那么PHP输出也是正确的:es-ES,es;q=0.8;en-US,en;q=0.5
。
为什么Firefox for Linux中的PHP输出错误以及如何解决?提前谢谢。
编辑:这些是HTTP标头(我划掉了认证标头)
请求:
GET / HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:54.0) Gecko/20100101 Firefox/54.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Referer: https://localhost/
Cookie: PHPSESSID=crucsit7is3r6hvnd88k6q2rn5
Authorization: ########
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Pragma: no-cache
Cache-Control: no-cache
响应:
HTTP/1.1 200 OK
Date: Tue, 25 Jul 2017 20:39:21 GMT
Server: Apache/2.4.18 (Ubuntu)
Authentication-Info: ########
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 1301
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
答案 0 :(得分:0)
我实际上在尝试睡觉的时候找到了一个解决方案,只是因为Chrome做了几年前的事情。
感谢@Pointy试图提供帮助
因此,如果有人也遇到此问题,请执行以下步骤:
about:config
)。intl.accept_languages
变量。xx-Xx, xx
,例如de-DE, de
。最重要的部分是该变量必须将其状态从“默认”更改为“用户修改”。es-ES, es, en-US, en
(将es-ES, es
部分替换为您的值,例如fr-FR, fr, en-US, en
)