PHP language detection
<p>Im a hobbycoder that is trying to build his first 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 HTTP_ACCEPT_LANGUAGE i dont know where it gets it from tho..</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?? How do you think YouTube does this for example?</p>

<p>Would be great if some english, french, swedish or polish folks could visit my site and see if it includes the right file! So i know that it doesnt just work for me :)
<a href="http://jorm.homeftp.org/" rel="nofollow">http://jorm.homeftp.org/</a></p>

<p>Anyway you think I could improve my code? it it will looks messy as i add more languages with all those elseif!</p>

<p>Thanks</p>
