美好的一天,php語言自動重定向
我的網站有EN,RU,AZ語言。我怎樣才能讓腳本自動更改語言的位置? 這個腳本工作:
function getLocationInfoByIp(){
$client = @$_SERVER['HTTP_CLIENT_IP'];
$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
$remote = @$_SERVER['REMOTE_ADDR'];
$result = array('country'=>'', 'city'=>'');
if(filter_var($client, FILTER_VALIDATE_IP)){
$ip = $client;
}
elseif(filter_var($forward, FILTER_VALIDATE_IP)){
$ip = $forward;
}
else{
$ip = $remote;
}
$ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));
if($ip_data && $ip_data->geoplugin_countryName != null){
$result['country'] = $ip_data->geoplugin_countryCode;
$result['city'] = $ip_data->geoplugin_city;
}
return $result;
}
$location = getLocationInfoByIp();
$loc= $location['country'];
它有助於找到地區代碼。恩。阿塞拜疆AZ,俄羅斯RU
如何使用if編寫重定向代碼? ex。如果位置AZ重定向到mysite.com/az/
如果位置RU重定向到mysite.com/ru/
那麼所有其他地區應該重定向到mysite.com/en/
得益於良好的天
感謝快速回答。 – Vaska