根据客户端选择不同网页语言

5

PHP代码:

<?php
if(preg_match("/zh-cn/is",$_SERVER['HTTP_ACCEPT_LANGUAGE'])){
@header("Location:http://www.sina.com.cn");
}else{
@header("Location:http://www.sohu.com");
}
?>


ASP代码:

<%
dim re
re = New RegExp
re.Pattern = "zh-cn"
re.IgnoreCase = true
re.Global = true
if re.Test(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")) then
Response.Redirect("http://www.sina.com.cn")
else
Response.Redirect("http://www.sohu.cn")
end if
%>

JavaScript代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="utf-8" >
<head>
<meta http-equiv="content-type"
content="text/html; charset=utf-8" />
<title>Redirect URL</title>
</head>
<body>
<script language="javascript" type="text/javascript">
var language = window.navigator.userLanguage ||
window.navigator.language;
if(/zh-cn/ig.test(language)){
location.replace("http://www.sina.com.cn");
}else{
location.replace("http://www.sohu.com");
}
</script>
</body>
</html>

共 5 条评论

  1. 回复

    y@evlos: 也许这也能从某种程度上证明PHP代码最有效率吧 ,哈哈·· 😕

  2. 回复

    嘻嘻,果然还是PHP语言写起来最短 ~ O(∩_∩)O ~
    订阅你咯,嘎嘎嘎 ~

  3. 回复

    好有学问啊!!

    :mrgreen:

  4. 回复

    @cyusyu: 双语外贸站用的比较多,就跟GOOGLE.COM在中国访问中文,在美国访问时英文一个道理。

  5. 回复

    不太明白 🙄

回复 cyusyu X

您的邮箱不会公开,当您的评论有新的回复时,会通过您填写的邮箱向您发送评论内容。 必填字段 *

为何看不到我发布的评论?

正在提交, 请稍候...