I'm using exactly this piece of code:
<?php
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
switch ($lang){
    case "fr":
        //echo "PAGE FR";
        include("index_fr.php");//include check session FR
        break;
    case "it":
        //echo "PAGE IT";
        include("index_it.php");
        break;
    case "en":
        //echo "PAGE EN";
        include("index_en.php");
        break;        
    default:
        //echo "PAGE EN - Setting Default";
        include("index_en.php");//include EN in all other cases of different lang detection
        break;
}
?>
to detect browser language as suggested in this question. But it's not properly detecting the right language. While javascript does things right with:
window.navigator.userLanguage || window.navigator.language;
php detects a different language. So let's say I'm running an italian browser, in Italy, then everything works fine BUT if I change my browser preferences and set it to english then js works properly but php still detects italian. I don't think I understand how this works and how to fix it.
I think it's because of the Accept-Language header which is still italian, but I don't really know how to deal with it or if my guess is right. Any help would be much appreciated!
 
    