欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP之判断用户语言跳转网页

程序员文章站 2022-05-29 13:05:29
...
当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。

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编程入门,请关注PHP中文网。