php根據(jù)用戶語言跳轉(zhuǎn)相應網(wǎng)頁
更新時間:2015年11月04日 15:46:42 投稿:lijiao
這篇文章主要介紹了php根據(jù)用戶語言跳轉(zhuǎn)相應網(wǎng)頁的方法,主要區(qū)分國內(nèi)國外,感興趣的小伙伴們可以參考一下
當來訪者瀏覽器語言是中文就進入中文版面,國外的用戶默認瀏覽器不是中文的就跳轉(zhuǎn)英文頁面。
<?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網(wǎng)頁根據(jù)來訪這的瀏覽器語言不同自動跳轉(zhuǎn)多語言頁面
在 <head> </head> 之間加入如下代碼。
以下為引用的內(nèi)容:
<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 判斷用戶語言跳轉(zhuǎn)網(wǎng)頁的全部內(nèi)容,內(nèi)容很簡單,希望大家可以學以致用。
相關(guān)文章
解決ThinkPHP關(guān)閉調(diào)試模式時報錯的問題匯總
本文給大家匯總了一下個人在項目中所遇到的關(guān)閉ThinkPHP的調(diào)試模式時遇到報錯的幾種情況以及最終的處理辦法,非常的簡單實用,這里分享給大家,有需要的小伙伴可以參考下。2015-04-04

