PHP Language Detection

There is a very simple method to detect what language the users web browser is using.

The following code:


//session variable ensures it's available
//throughout current session

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

Multilingual
Will give you the correct two letter ISO code for the language the browser is using.

Tags: , , ,

Leave a Comment

You must be logged in to post a comment.