将页面刷新到新状态

发布于 2024-08-20 03:54:07 字数 192 浏览 1 评论 0原文

我使用 php 和 mysql 编写了一个 博客,它具有登录功能。当您注销并返回时,它不应该显示会员的功能,因为您不再登录。我如何更正它,以便当用户不再登录并返回按钮时,上一页应该是是在他登录之前的状态吗?

I have a written a blog using php and mysql which has a login feature. When you are logged out and hit back it should not show the features of a member since you are no longer logged in. How do I correct it so that when a user is no longer logged in and hit back button, the previous page should be in the state before he logged in?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

为人所爱 2024-08-27 03:54:07

很难辨别您使用的身份验证机制,但假设这是一个纯粹的缓存问题,您可以将以下语句添加到登录时显示的所有 .php 页面的开头。

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 1 Jan 1970 05:00:00 GMT");

这应该可以解决缓存问题。并确保您unset()用于跟踪用户是否登录的访问变量(在$_SESSION或类似的形式中)。

It's hard to discern what authentication mechanism you're using, but assuming this is a pure caching issue you can add the following statements to the beginning of all .php pages displayed while logged in.

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 1 Jan 1970 05:00:00 GMT");

That should take care of caching issues. And make sure that you unset() the access variable you used to keep track of wether or not the user is logged in (in $_SESSION or similar).

南七夏 2024-08-27 03:54:07

这是浏览器的功能。但不用担心,如果您没有实际登录,您将无法实际执行任何管理级别的操作。如果您愿意,您可以通过以下方式向服务器发出请求javascript 在加载页面时询问用户是否登录。如果该请求返回 false,您可以隐藏管理控件,或将用户重定向到索引页面。

您可以在代码中明确声明您希望不缓存页面,但这会降低访问者体验,并给服务器带来更多开销。我不认为该特定解决方案的目的证明了手段的合理性。

This is a browser feature. But don't worry, you won't be able to actually do any admin-level stuff if you're not actually logged in. If you wanted, you could fire off a request to the server via javascript to ask if the user is logged in upon loading a page. If that request comes back false, you can hide the admin controls, or redirect the user to the index page.

You could explicitly state in code that you wish to not cache the pages, but that will slow down visitor-experience, and cause more overhead for your server. I don't think the ends justify the means in that particular solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文