PHP Web pages automatically jump to Chinese and English pages based on different browser languages
Demo: http://www.gabion.cn
When the visitor's browser language is Chinese, the Chinese version is displayed.
Overseas users jump to the English page if the browser is not Chinese by default.
PHP code:
<?
$ Lan = substr ($ HTTP_ACCEPT_LANGUAGE, 0, 5 );
If ($ lan = "zh-cn ")
Print ("<meta http-equiv = 'refresh' content = '0; URL = gb/index.htm '> ");
Else
Print ("<meta http-equiv = 'refresh' content = '0; URL = eng/index.htm '> ");
?>
HTML web pages automatically jump to multilingual pages based on different browser languages
Add the following code between
<Script>
Var type = navigator. appName
If (type = "Netscape ")
Var lang = navigator. language
Else
Var lang = navigator. userLanguage
// Cut down to first 2 chars of country code
Var lang = lang. substr (0, 2)
// English
If (lang = "en ")
Window. location. replace ('url ')
// Simplified Chinese
Else if (lang = "zh-cn ")
Window. location. replace ('url ')
// Traditional Chinese
Else if (lang = "zh-tw ")
Window. location. replace ('url ')
// German
Else if (lang = "de ")
Window. location. replace ('url ')
// Except the languages listed above
Else
Window. location. replace ('url ')
</Script>