Many sites on the home page to do some of the links, so that users can choose to visit the respective language page, let the Chinese people choose "Chinese", Koreans choose "Korean", and so on. So can you do a program to automatically help you choose?
The answer is yes, everyone is using Google, you use the Chinese system to open the Google homepage, open the nature is the Chinese home page, and will not be other languages. Because Google automatically determines what the preferred language is for the user's system to use.
How to do it like Google, in fact, very simple,
This information is included in the HTTP Headers information that the browser sends to the Web server Accept-language
The message is that the tool->internet option in the browser-> the language that is used to set the browser's acceptable language preferences, which can be a priority sequence for a variety of acceptable languages.
Let's take PHP for example,
User-acceptable language information, placed in $_server[' Http_accept_language ',
Variable information is similar to "ZH-CN", if it is a multilingual column, is similar to "zh-cn,en;q=0.8,ko;q=0.5,zh-tw;q=0.3"
The following questions can be solved.
<?php
Error_reporting (e_all ^ e_notice);
Analyzing the properties of Http_accept_language
Only the first language settings are available (other enhancements can be made as needed, only simple methods are shown here)
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
}
?>