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扩展mcrypt实现的AES加密功能示例

PHP扩展mcrypt实现的AES加密功能示例

本文实例讲述了PHP扩展mcrypt实现的AES加密功能。分享给大家供大家参考,具体如下: AES(Advanced Encryption Standard,高级加密标准)是美国联邦政府...

提高PHP编程效率的方法

1、如果能将类的方法定义成static,就尽量定义成static,它的速度会提升将近4倍。2、$row['id'] 的速度是$row[id]的7倍。3、echo 比 print 快,并且...

PHP之数组学习

今天学习了数组,可以说是PHP的数据应用中较重要的一种方式。PHP的数组函数众多,下面是我学习的小结,借此记之,便于以后鉴之……   一、数组定义:   数组的定义使用 array()方...

php实现微信公众平台账号自定义菜单类

本文实例讲述了php实现微信公众平台账号自定义菜单类的方法。分享给大家供大家参考。具体分析如下: 微信公众平台服务号可申请自定义菜单了,其它的号暂时不支持自定义菜单了,这个不但可以使用a...

Wordpress php 分页代码

Wordpress php 分页代码

效果: 将下面的函数放到你的主题的 functions.php 文件中:复制代码 代码如下: function theme_echo_pagenavi(){ global $reque...