Home  >  Article  >  Backend Development  >  PHP determines user language and jumps to web page_PHP tutorial

PHP determines user language and jumps to web page_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:34:42772browse

When the visitor’s browser language is Chinese, enter the Chinese page
If the default browser for foreign users is not Chinese, they will jump to the English page

PHP code:
$lan = substr( $HTTP_ACCEPT_LANGUAGE,0,5);
if ($lan == "zh-cn")
print("");
else
print("");
?>


HTML web pages automatically jump to multi-language pages based on the language of the browser you visit

Add the following code between . php programmer station
The following is the quoted content:
<script> <br> var type=navigator.appName <br> if (type=="Netscape") <br> var lang = navigator.language <br> else <br> var lang = navigator.userLanguage</p> <p>//cut down to first 2 chars of country code <br> var lang = lang.substr(0,2)</p> <p>// English<br> if (lang == "en") <br> window.location.replace(url)</p> <p>// Simplified Chinese<br> else if (lang == "zh-cn") <br> window.location.replace(url)</p> <p>// Traditional Chinese<br> else if (lang == "zh-tw") <br> window.location.replace(url)</p> <p>// German<br> else if (lang == "de") <br> window.location.replace(url)<br> //Except the languages ​​listed above<br> else <br> window.location.replace(url)</p> <p></script>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508437.htmlTechArticleWhen the visitor’s browser language is Chinese, enter the Chinese page. Foreign users whose default browser is not Chinese will jump English page PHP code: ? $lan = substr($HTTP_ACCEPT_LANGUAGE,0,5);...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn