我的作法是先查詢瀏覽器預設語言
如果沒有值再結合GEOIP去查詢所在地點,作為當地語言參考
真的都沒有的話,只好預設英語

if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']))
{
preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
$lang = $matches[1];
}
$hl = 'en-us';
//echo is_dir('./language/'.strtolower($lang));
if(empty($lang) || !is_dir('./language/'.strtolower($lang)))
{
$ip = $this->input->ip_address();
include("libraries/geoip.inc");
$gi = geoip_open("libraries/GeoIP.dat",GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $ip);
if($country_code)
{
$country_code = strtolower($country_code);
$hl = $this->_switchcountry($country_code);
}
else{
$hl = 'en-us';
}
}
elseif(!empty($lang) && is_dir('./language/'.strtolower($lang))){
$hl = strtolower($lang);
}
else {
$hl = 'en-us';
}
arrow
arrow
    全站熱搜

    Matt 發表在 痞客邦 留言(0) 人氣()