Detecting browser language before loading page and changing language depends on the user is very common and user friendly application.
In the following code first line will detect the language of the browser.
In the second line we will determine the languages we use in the website.
Third line will check if browser language in our usable range or not. If it is not in the range, code will automatically select the English.
$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
$webDictionary = ['en', 'de', 'tr'];
$language = in_array($language, $webDictionary) ? $language : 'en';