萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> php如何自動跳轉中英文頁面

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>
copyright © 萬盛學電腦網 all rights reserved