Many sites on the home page to do some links, so that users to select the respective language pages will be visited, so that Chinese people choose "Chinese", South Koreans choose "Korean", and so on. So can you do a program to automatically help choose?
The answer is yes, everyone is using Google, you use the Chinese system to open Google's homepage, open the natural is the Chinese home page, but not other languages. Because Google automatically determines the preferred language used by the user's system.
How to do it like Google, in fact, is very simple,
This information is included in the HTTP Headers information that the browser sends to the Web server Accept-language
This information is the language in the browser, the Tools->internet option, which is used to set the browser's acceptable language preference, which can be a prioritized sequence of multiple acceptable languages.
Let's take PHP for example,
User-acceptable language information, placed in $_server[' Http_accept_language '],
Variable information is similar to the "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 questions can be solved.
Error_reporting (e_all ^ e_notice);
Analyzing the properties of a http_accept_language
Only the first language settings are available here (others can be enhanced as needed, just a simple way to demonstrate)
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
}
?>
http://www.bkjia.com/PHPjc/314059.html www.bkjia.com true http://www.bkjia.com/PHPjc/314059.html techarticle Many sites on the home page to do some links, so that users to select the respective language pages will be visited, so that Chinese people choose "Chinese", South Koreans choose "Korean", and so on. So can ...