Using PHP code to realize automatic judgment turning of Web page

Source: Internet
Author: User

User-acceptable language information, placed in $_server[' http_accept_language ', variable information is similar to "ZH-CN", if it is a multilingual 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.

Code:

<?php
Error_reporting (e_all ^ e_notice);
Analyzing the properties of Http_accept_language
Only the first language settings are available (other enhancements can be made as needed, only simple methods are shown here)
Preg_match ('/^ ([a-z\-]+)/I ', $_server[' http_accept_language '], $matches);
$lang = $matches [1];
Switch ($lang) {
Case ' ZH-CN ':
Header (' location:http://cn.example.com/');
Break
Case ' ZH-TW ':
Header (' location:http://tw.example.com/');
Break
Case ' KO ':
Header (' location:http://ko.example.com/');
Break
Default
Header (' location:http://en.example.com/');
Break
}
?>

Please contact the site, timely note your name. Contact Email: edu#chinaz.com (change # to @).



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.