Make use of PHP code to automatically turn pages

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags code error_reporting example http information it is location multi-language

User-friendly language information on _SERVER [HTTP_ACCEPT_LANGUAGE]
Variable information is similar to this "zh-cn", if it is multi-language 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);
// Analyze the properties of HTTP_ACCEPT_LANGUAGE
// Here only take the first language settings (others can be enhanced as needed, here only a simple method to demonstrate)
preg_match (/ ^ ([az -] +) / 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;
}
?>

Related Article

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.