The user's acceptable language information is put in $ _ SERVER ['HTTP _ ACCEPT_LANGUAGE '], and the variable information is similar to this "zh-cn". If it is a multi-language column, is similar to "zh-cn, en; q = 0.8, ko; q = 0.5, zh-tw; q = 0.3"
The following problems can be solved.
Code:
<? Php
Error_reporting (E_ALL ^ E_NOTICE );
// Analyze the HTTP_ACCEPT_LANGUAGE attributes
// Here, only the first language settings are used (other functions can be enhanced as needed. Here, we will only make a simple demonstration)
Preg_match ('/^ ([a-z-])/I', $ _ SERVER ['HTTP _ ACCEPT_LANGUAGE '], $ matches );
$ Lang = $ matches [1];
Switch ($ lang ){
Case 'zh-cn ':
Header ('location: http://cn.example.com /');
Break;
Case 'zh-tw ':
Header ('location: http://tw.example.com /');
Break;
Case 'ko ':
Header ('location: http://ko.example.com /');
Break;
Default:
Header ('location: http://en.example.com /');
Break;
}
?>