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 curl上传、下载、https登陆实现代码

1、curl下载 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "ftp://127.0.0.1/downtest.txt");...

关于访问控制的一首PHP面试题(对属性或方法的访问控制)

复制代码 代码如下: class Foo { private $name = 'hdj'; public function getName(){ return $this->nam...

PHP字符串函数系列之nl2br(),在字符串中的每个新行 (\n) 之前插入 HTML 换行符br

nl2br()定义和用法 nl2br() 函数在字符串中的每个新行 (\n) 之前插入 HTML 换行符 (<br />)。 语法 nl2br(string)参数 描述 st...

应用开发中涉及到的css和php笔记分享

关于应用中遇到的一些问题及解决办法,做一些记录,以备后用。本人新手,技术还不熟练,笔记比较幼稚。嘲笑请轻笑。   1、关于层的绝对定位。   有两个div层,其中main类div是整体的...

非常实用的php验证码类

本文实例为大家分享了php验证码类,供大家参考,具体内容如下 <?php /** * * @author Administrator * */ cl...