Auto change the country list dropdown based on web browser languages
Submitted by chrislim2888 on Thursday, January 24, 2013 - 23:45.
Language
The following codes populate the country list into dropdown box based on browser's languages. The country information is getting from geolocation.com, free license with attribution: The geolocation data is provided by http://www.geolocation.com
Browser Languages: ' . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . '';
echo 'Country List The geolocation data is provided by http://www.geolocation.com
';
////////////////////////////
//Get the browser languages
if(preg_match_all('/([a-z]{1,8}(-[a-z]{1,8})?)\s*(;\s*q\s*=\s*(1|0\.[0-9]+))?/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $lang_matches)){
$langs = array_combine($lang_matches[1], $lang_matches[4]);
foreach ($langs as $lang => $val)
if ($val === '') $langs[$lang] = 1;
arsort($langs, SORT_NUMERIC);
}
//Default to english
$language = 'en-us';
foreach ($langs as $lang => $val){
$language = $lang;
break;
}
//////////////////////
//Load the Country File
//Notes:
//Download the CSV file from http://www.geolocation.com
//Rename the CSV to country-en-us.csv (for english version),
//country-zh-cn.csv (for chinese simplified version),
//country-zh-tw.csv (for chinese traditional version)
//and save in the same folder as the php code resided.
echo '';
}
else
echo 'Unable to locate browser languages';
?>
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Add new comment
- 116 views