可以根据浏览器传过来的ACCEPT_LANGUAGE来判断,代码如下:
<?php
preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
$lang = $matches[1];
switch ($lang) {
case 'zh-CN' :
//header('Location: http://cn.test.com/');
echo "中国";
break;
case 'zh-TW' :
// header('Location: http://tw.test.com/');
echo "台湾";
break;
case 'KO' :
//header('Location: http://ko.test.com/');
break;
default:
// header('Location: http://en.test.com/');
echo "英文";
break;
}
网友回复