Many websites provide links on the homepage to allow users to select their respective language pages, Chinese as the Chinese, and Korean as the Korean. So can I make a program to automatically help with the selection?
The answer is yes. Everyone is using google. If you open google's homepage in a Chinese system, you will naturally open the Chinese homepage instead of other languages. Because google will automatically determine the preferred language used by the user system.
How can we make it as simple as google,
The HTTP Headers Information sent from the browser to the web server contains the Accept-Language Information.
This information is the tool in the browser-> Internet Options-> general language, which is used to set acceptable language preferences of the browser, it can be a priority column in multiple acceptable languages.
The following uses PHP as an example,
The user's acceptable language information is stored in $ _ SERVER ['HTTP _ ACCEPT_LANGUAGE,
The variable information is similar to "zh-cn". For multi-language columns, it is similar to "zh-cn, en; q = 0.8, ko; q = 0.5, zh-tw; q = 0.3"
The following problems can be solved.
<? 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: [url] http://cn.example.com/#/url#');
Break;
Case 'zh-tw ':
Header ('location: [url] http://tw.example.com/#/url#');
Break;
Case 'ko ':
Header ('location: [url] http://ko.example.com/#/url#');
Break;
Default:
Header ('location: [url] http://en.example.com/#/url#');
Break;
}
?>