Many websites provide links on the homepage to allow users to select their respective language pages to be visited, Chinese for Chinese, Korean for Korean, and so on. So can we make a program to help you choose? The answer is OK.
Many websites provide links on the homepage to allow users to select their respective language pages to be visited, Chinese for Chinese, Korean for Korean, and so on. So can we make a program to help you choose?
The answer is yes. everyone is using google. you can use a Chinese system to open the google homepage. Naturally, the Chinese homepage is not used in other languages. Because google will determine the preferred language for user system applications.
How can we be as simple as google,
The HTTP Headers Information sent from the browser to the web server contains the Accept-Language Information, which is the Language in the browser tool> Internet Options> convention, it is used to set the browser's acceptable language preferences. it can be a priority column for multiple languages.
The following uses PHP as an example to describe the language information that users can receive in $ _ SERVER ['http _ ACCEPT_LANGUAGE ']. the variable information is similar to 'zh-cn ', for a multi-language column, the title is similar to 'zh-cn, en; q = 0.8, ko; q = 0.5, zh-tw; q = 100.
Error_reporting (E_ALL ^ E_NOTICE );
// Analyze the HTTP_ACCEPT_LANGUAGE attributes
// Here we only use the first language settings (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;
}
?>