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

PHPz
發布: 2018-11-13 15:53:38
原創
1336 人瀏覽過


当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。

PHP代码:

<? 
$lan = substr(?$HTTP_ACCEPT_LANGUAGE,0,5); 
if ($lan == "zh-cn") 
print("<meta http-equiv=&#39;refresh&#39; content = &#39;0;URL = gb/index.htm&#39;>"); 
else 
print("<meta http-equiv=&#39;refresh&#39; content = &#39;0;URL = eng/index.htm&#39;>"); 
?>
登入後複製

HTML网页根据来访这的浏览器语言不同自动跳转多语言页面,在 之间加入如下代码。

<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(&#39;url&#39;) 
// 简体中文 
else if (lang == "zh-cn") 
window.location.replace(&#39;url&#39;) 
// 繁体中文 
else if (lang == "zh-tw") 
window.location.replace(&#39;url&#39;) 
// 德语 
else if (lang == "de") 
window.location.replace(&#39;url&#39;) 
// 除上面所列的语言 
else 
window.location.replace(&#39;url&#39;) 
</script>
登入後複製

以上就是对PHP之判断用户语言跳转网页的全部介绍,如果您想了解更多有关php编程入门,请关注PHP中文网。



來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!