PHP 页面会记住访问者的选择,以便在下次访问时自动转发它们
经过广泛的研究,我无论如何都找不到解决方案,这令人沮丧,经过几天的砸键盘、对着天空大喊大叫、长时间蜿蜒散步来平静下来——我们都经历过这样的情况!但更糟糕的是,我很确定我的发际线已经后退了很多...
我发现,要么嗅出 IP 来自动重定向你,要么使用表单来设置 cookie,但没有任何帮助,很遗憾。
- 我有一个 PHP 国家/地区登陆页面 在 WordPress 模板中。
- 它有 2 张图片,一张是英国, 指向 [domain]/UK,另一个是 IE 并指向[域]/IE。
- 当用户最初点击他们的 国家/图像,我想要一块饼干 被设置。
- 所以下次他们去那里的时候 页面,他们被定向到他们的 自动初始选择。
- 参考站点在这里: http://goo.gl/9hEI8
我已经尝试并尝试让一些东西起作用,但我我就是无法理解这个问题。
帮助我吧,奥比万·克诺比,你是我唯一的希望,谢谢!
After extensive research, I can't find the solution anyway for this, and it's frustrating and after days of smashing the keyboard, shouting at the sky and taking long meandering walks to calm down - we've all been there! But what's worse, I'm pretty sure my hairline has receded a fair bit from all this...
What I have found, either sniff out the IP to automatically redirect you or uses a form to set the cookie, non of which help, unfortunately.
- I have a PHP country landing page
within a WordPress template. - It has 2 images, one is UK and
points to [domain]/UK, the other is
IE and points to [domain]/IE. - When a user initially clicks their
country/image, I'd like a cookie to
be set. - So the next time they visit that
page, they're directed to their
initial selection automatically. - Reference site here: http://goo.gl/9hEI8
I've tried and tried to get something working but I just can't get my head around this one.
Help me Obi Wan Kenobi your my only hope, thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您需要识别用户。最简单的方法是在访问者的浏览器中存储 HTTP cookie。
您可以使用 PHP、JavaScript 进行设置,这并不重要,因为无论您选择哪种方法,存储的 cookie 都是相同的。但您需要注意,HTTP cookie 的最长期限需要设置为一个月左右。
在第二次访问时,您检查服务器端存储的 cookie 并将用户重定向到所选页面(但请记住,应该有一个选项可以更改第一个决定)。
因此,步骤如下:
$_COOKIE
数组),setcookie
例如,header("位置...")
重定向First of all you need to identify the user. The easiest way is to store an HTTP cookie in the visitors' browser.
You can set this with PHP, JavaScript, it does not matter because the stored cookie will be the same regardless of the method you select. But you need to aware of that the maximal age of the HTTP cookie needs to be set to a month or so.
On the second visit you check the stored cookie on the server side and redirects the user to the selected page (but keep in mind that an option should be there to change this first decision).
So, the steps:
$_COOKIE
array in PHP)setcookie
for exampleheader("Location ...")
redirect