Automatically identifies the browser language to switch between Chinese and English (php and Js)

Source: Internet
Author: User
Automatically identifies the browser language to switch between Chinese and English (php and Js)

  1. Error_reporting (E_ALL ^ E_NOTICE );
  2. // Analyze the HTTP_ACCEPT_LANGUAGE attributes
  3. // Only set the first language here (other functions can be enhanced as needed)
  4. // Search for finishing bbs.it-home.org
  5. Preg_match ('/^ ([a-z \-] +)/I', $ _ SERVER ['http _ ACCEPT_LANGUAGE '], $ matches );
  6. $ Lang = $ matches [1];
  7. Switch ($ lang ){
  8. Case 'zh-cn ':
  9. Header ('Location: http://cn.jbxue.com /');
  10. Break;
  11. Case 'zh-tw ':
  12. Header ('Location: http://tw.jbxue.com /');
  13. Break;
  14. Case 'Ko ':
  15. Header ('Location: http://ko.jbxue.com /');
  16. Break;
  17. Default:
  18. Header ('Location: http://en.jbxue.com /');
  19. Break;
  20. }
  21. ?>

2. JS-based method:

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.