php根据用户语言跳转相应网页

yipeiwu_com6年前PHP代码库

当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。

<?php 
$lan = substr( $HTTP_ACCEPT_LANGUAGE,0,5); 
if ($lan == "zh-cn") 
print("<meta http-equiv='refresh' content = '0;URL = gb/index.htm'>"); 
else 
print("<meta http-equiv='refresh' content = '0;URL = eng/index.htm'>"); 
?> 

HTML网页根据来访这的浏览器语言不同自动跳转多语言页面
<head> </head> 之间加入如下代码。
以下为引用的内容:

<script> 
var type=navigator.appName 
if (type=="Netscape") 
var lang = navigator.language 
else 
var lang = navigator.userLanguage 
 
//cut down to first 2 chars of country code 
var lang = lang.substr(0,2) 
 
// 英语 
if (lang == "en") 
window.location.replace('url') 
 
// 简体中文 
else if (lang == "zh-cn") 
window.location.replace('url') 
 
// 繁体中文 
else if (lang == "zh-tw") 
window.location.replace('url') 
 
// 德语 
else if (lang == "de") 
window.location.replace('url') 
// 除上面所列的语言 
else 
window.location.replace('url') 
 
</script> 

以上就是PHP 判断用户语言跳转网页的全部内容,内容很简单,希望大家可以学以致用。

相关文章

PHP日期时间函数的高级应用技巧

checkdate($month,$date,$year)如果应用的值构成一个有效日期,则该函数返回为真。例如,对于错误日期2005年2月31日,此函数返回为假。在日期用于计算或保存在数...

php的webservice的wsdl的XML无法显示问题的解决方法

php的webservice的因为wsdl有中文所以xml无法显示 可以用Nopepad++  转码即可  以UTF-8无BOM编码...

php excel类 phpExcel使用方法介绍

下载地址:http://www.codeplex.com/PHPExcel   下面是总结的几个使用方法   include ‘PHPExcel.php';   include ‘PHP...

discuz图片顺序混乱解决方案

discuz图片顺序混乱解决方案

说明 discuz在发表帖子的时候,添加多张图片,然后直接发表帖子,图片顺序有时候会乱掉 即使上传图片窗口中图片顺序正确,发布之后还是会乱掉 分析 看url,程序代码中看不出什么 将图片...

php将数据库导出成excel的方法

上传cvs并导入到数据库中,测试成功(部分代码不规范,如PHP_SELF那里要改写成$_SERVER["PHP_SELF"] ) PHP代码 复制代码 代码如下: <?php $f...