Last active
December 16, 2015 02:39
-
-
Save mondalaci/5363944 to your computer and use it in GitHub Desktop.
Detect primary language by HTTP Accept-Language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$accepted_languages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']); | |
$primary_language = $accepted_languages[0]; | |
if ($pos=strpos($primary_language, ';') !== false) { | |
$primary_language = substr($primary_language, 0, $pos+1); // Throw away quality value. | |
} | |
if ($pos=strpos($primary_language, '-') !== false) { | |
$primary_language = substr($primary_language, 0, $pos+1); // Throw away dialect. | |
} | |
header("Location: http://mysite.com/$primary_language")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment