Automatically jump to Chinese and English pages _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Automatically jump to the Chinese and English pages. PHP web pages automatically jump to Chinese and English pages based on different browser languages: www.gabion.cn when the visitor's browser language is Chinese, the Chinese version of the user's mophp web page will automatically jump to the Chinese and English pages based on the browser language.
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 (" ");
Else
Print (" ");
?>

HTML web pages automatically jump to multilingual pages based on different browser languages


In Add the following code.

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

Guest demo: http://www.gabion.cn when the visitor browser language is Chinese language to enter the Chinese version of foreign users mo...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.