Home > php教程 > php手册 > 利用PHP代码实现网页自动判断转向的实例

利用PHP代码实现网页自动判断转向的实例

WBOY
Release: 2016-06-21 09:00:55
Original
1209 people have browsed it

用户可接受的语言信息,放在$_SERVER['HTTP_ACCEPT_LANGUAGE']里,
 
变量信息是类似这样的 "zh-cn", 如果是多语言列,是类似 "zh-cn,en;q=0.8,ko;q=0.5,zh-tw;q=0.3"

下面的问题可以迎刃而解了。

error_reporting(E_ALL ^ E_NOTICE);
// 分析 HTTP_ACCEPT_LANGUAGE 的属性
// 这里只取第一语言设置 (其他可根据需要增强功能,这里只做简单的方法演示)
preg_match('/^([a-z\-]+)/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'], $matches);
$lang = $matches[1];
switch ($lang) {
       case 'zh-cn' :
               header('Location: http://cn.webjx.com/');
               break;
       case 'zh-tw' :
               header('Location: http://tw.webjx.com/');
               break;
       case 'ko' :
               header('Location: http://ko.webjx.com/');
               break;
       default:
               header('Location: http://en.webjx.com/');
               break;
}
?>



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template