• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

详解PHP如何根据用户语言跳转对应网页

php 搞代码 3年前 (2022-01-22) 19次浏览 已收录 0个评论

本文主要介绍了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<span>@本文来*源gaodai#ma#com搞*!代#%^码$网*</span><textarea>搞gaodaima代码</textarea>')  // 简体中文 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对xml文件增删改查

详解php7如何实现MongoDB模糊查询

详解PHP如何实现csv文件导入数据库

以上就是详解PHP如何根据用户语言跳转对应网页的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:详解PHP如何根据用户语言跳转对应网页

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址