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解决和避免form表单重复提交的几种方法

前言 为什么要避免form表单被重复提交呢?因为我们不想让我们的服务器重复处理没必要的数据,同时我们也是避免我们的数据库产生重复的数据,避免表单重复提交也是让我们的网站更安全的一种表现。...

linux下删除7天前日志的代码(php+shell)

PHP版本: 复制代码 代码如下: /** * 删除7天前的日志 * @param $logPath */ function del7daysAgoLog($logPath) { if(...

php定义参数数量可变的函数用法实例

本文实例讲述了php定义参数数量可变的函数用法。分享给大家供大家参考。具体分析如下: php中的的函数参数可以不固定,甚至不用定义参数,在函数内部使用func_get_args()函数获...

PHP读取大文件的多种方法介绍

读取大文件一直是一个头痛的问题,我们像使用php开发读取小文件可以直接使用各种函数实现,但一到大文章就会发现常用的方法是无法正常使用或时间太长太卡了,下面我们就一起来看看关于php读取大...

php session 错误

1. 错误提示 Warning: Cannot send session cookie - headers already sent Warning: Cannot send sessi...