PHP Get browser Language

In php you can get the language of your visitor, this is very helpful if you have many versions of your website for different languages.

You can get the language of your visitor in this way:
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);

This will give you the 2letter language code, ie: en for english and fr for french .

In fact $_SERVER['HTTP_ACCEPT_LANGUAGE'] will get all language the user prefer to use, in order. So substr() will give you the first choice, you can also get the second choice, the third ...

Having the language of your visitor will let you display custom page depending on his language, for example if someone's language is french, you will have $lang="fr" , then you can redirect him to or to show him your website in french, or show him things related to french language, whatever your website is about.


Anonymous said...

Thanks for that useful info.

rize wordpress said...

Our PHP Developers have excellent skills in content management system (CMS), collaborative networking systems, shopping carts, testing, implementations, portals and most important online business application development.

LOL elo boost said...

Amazing because typical! This can be my personal very first time commenting however I've been subsequent your site for a long time: )#) adore the appearance upon EACH from the felines encounters; )#) extremely adorable hair styles, as well.

League of Legends boost

Cheap Fifa 14 Ultimate Team Coins

Anonymous said...

Thanks for this, I have used it as a base for determining a users location and language to show different information to those in the US then those in other countries. You can see it at

Lucky Srivastava said...

Hey Very nice Blog,Thanks For Sharing..

Python training in Lucknow
Softpro Learning Center
best Php training center
Best python training in lucknow

Lucky Srivastava said...

Hey Nice blog,Thanks for sharing this blog.!!!

Best Summer training in lucknow

Best Php training in lucknow

Summer training in lucknow

Summer training Company in lucknow

sai pallavi said...

Really incredible and interesting article. Keep the good work. I really appreciate your effort on putting such thoughts in the post. Thanks for sharing with us. Latest php jobs in hyderabad