如何根据浏览器语言重定向用户
我想根据浏览器语言重定向用户,我在这里弄清楚了如何做到这一点,它工作正常,这是代码(PHP):
if(preg_match('/en-US/', $_SERVER['HTTP_USER_AGENT'])) 标题(“位置:index.php”); 别的 header("位置:http://cn.gearor.com");
问题是我只想重定向来自其他网站或首次访问我的网站的用户。这意味着我不希望用户阅读我网站的某些页面,当他们返回索引时,他们会被重定向到其他页面。而且我的网站上也有一个链接,例如:英文或中文,当用户从中文页面点击英文时,他们会转到index.php并被重定向回中文页面,这使得用户无法访问英文页面。如何在 PHP 或 JavaScript 中解决此问题?
I want to redirect users based on browser language, I figured out how to do this here, it works fine, here is the code(PHP):
if(preg_match('/en-US/', $_SERVER['HTTP_USER_AGENT'])) header("location:index.php"); else header("location:http://cn.gearor.com");
The problem is I only want to redirect users from other websites or at the first visit to my website. Which means I don't want users reading some pages of my website, when they go back to index, they were redirect to other page. And I also have a link in my website, like: English or Chinese, when users click English from a Chinese page, they will go to index.php and been redirect back to Chinese page, it makes users can't visit the English page. How do I fix this in PHP or JavaScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置像 $_SESSION['lang'] 这样的会话变量,并且仅在未设置 $_SESSION['lang'] 时应用上面的代码。
我的意思是:
You can set a session variable like $_SESSION['lang'] and only apply the above code if $_SESSION['lang'] is not set.
what I mean is:
嗯,很难理解你在说什么,如果你能澄清一下的话,但这就是我认为你所要求的,粘贴箱。
Well it was hard to understant what you are saying, if you can reclarifiy a bit, but here is what I think you were asking for, Pastebin.