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

yipeiwu_com5年前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 判断用户语言跳转网页的全部内容,内容很简单,希望大家可以学以致用。

相关文章

利用phpexcel对数据库数据的导入excel(excel筛选)、导出excel

话不多说,请看代码: <?php date_default_timezone_set("PRC"); error_reporting(E_ALL); error_re...

php生成SessionID和图片校验码的思路和实现代码

/****** 产生Session ID ******/ 基本的思路: 是把当前微秒的时间获取, 然后产生以个随机数字, 把随机数字和当前时间相加后加密一下, 最后再截取需要的长度...

php观察者模式应用场景实例详解

本文实例讲述了php观察者模式的应用。分享给大家供大家参考,具体如下: <?php /** * 观察者模式应用场景实例 * * 免责声明:本文只是以哈票网举例,示...

php实现删除指定目录下相关文件的方法

本文实例讲述了php实现删除指定目录下相关文件的方法。分享给大家供大家参考。具体实现方法如下: 通常来说在php中删除文件最简单的方法就是直接使用unlink命令,而对于需要删除指定目录...

PHP函数积累总结

PHP函数积累总结

字符串 1、strtr(string,from,to)函数 把字符串中的字符from替换成to。 如果from和to长度不同,则格式化为最短的长度。   strtr(stri...