title: PHP language detection
body: <p>I'm  trying to build multilangual site.</p>
  
  <p>I use this piece of code to detect users language. If you havent chosen a language, it will include your language file based on <code>HTTP_ACCEPT_LANGUAGE</code>.</p>
  
  <p>I don't know where it gets it from though:</p>
  
  <pre><code>session_start();
  
  if (!isset($_SESSION['lang'])) {
     $_SESSION['lang'] = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
  }
  
  elseif (isset($_GET['setLang']) &amp;&amp; $_GET['setLang'] == 'en') $_SESSION['lang'] = "en";
  elseif (isset($_GET['setLang']) &amp;&amp; $_GET['setLang'] == 'sv') $_SESSION['lang'] = "sv";
  elseif (isset($_GET['setLang']) &amp;&amp; $_GET['setLang'] == 'pl') $_SESSION['lang'] = "pl";
  elseif (isset($_GET['setLang']) &amp;&amp; $_GET['setLang'] == 'fr') $_SESSION['lang'] = "fr";
  
  include('languages/'.$_SESSION['lang'].'.php');
  </code></pre>
  
  <p>It works for me and includes the polish lang file. But is this code accurate? Or is there another way?</p>