How to recognize user language in PHP

Is there a way to parse HTTP_USER_AGENT to get the current language of the user?

+3
source share
4 answers

Try:

$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
echo $lang;
+5
source

You might want to try HTTP_ACCEPT_LANGUAGE in the super _ global file $ _SERVER.

See http://php.net/manual/en/reserved.variables.server.php for more information.

This will return a value like "en-us", which can then be broken down as needed.

+2
source

User Agent, Accept-Language, , , !

+1

Another common way (how to create an alternative) for this is to check the user's IP address in relation to the IP address database with the corresponding regions. The most common database for this is GeoIP ( http://www.maxmind.com ). It’s worth a look if you are interested. Then you can move on to changing the language in the region.

Regards,
Dennis M.

0
source

Source: https://habr.com/ru/post/1754886/


All Articles