根据 ID 询问 Apache 会话是否仍然存在
我想知道如何根据给定的 ID 检查 PHP 会话是否仍然存在。那个或任何可以让我访问活动会话列表的东西。
我在网上找到了一些相关信息,但无法真正得到正确的答案。
为了告诉你一些背景知识,我正在编写一个网站,允许用户修改内容(例如,文章)。由于我不希望他们同时修改相同的资源,因此我必须考虑保护系统。
因此,我们的想法是每个打开的资源都将被锁定并与一个会话 ID 相关联。完成后,用户将释放它。但当然,没有什么可以阻止他关上窗口,让内容锁定在书面上。
因此,我必须能够检查会话是否仍然存在,以及锁是否仍然合法。
I would like to know how to check if an PHP session is still alive, thanks to a given ID. That or anything which could give me access to the active session's list.
I have found some related information on the internet, but couldn't really get a proper answer.
To tell you a bit about the background, I am writing a website which allows users to modify content (let's say articles, for instance). And since I don't want them to modify the same resource at the same time, I had to think about a protection's system.
So the idea was that each opened resource would be locked and associated with a session ID. When finished, the user would free it. But of course nothing prevents him from just closing the window, letting the content locked in writing.
Therefore I have to be able to check if a session is still alive, and if a lock is still legitimate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于您的问题,有一个非常简单的解决方案:
打开页面时,将用户 ID 和当前时间戳存储在用于锁定元素的某些列中。在页面上,包含一些 JavaScript,以便每分钟调用一些脚本来更新时间戳 - 因此,只要用户在此页面上,时间戳就永远不会早于 1 分钟。只需阻止其他人编辑同一元素,除非时间戳早于 1 分钟(以及几秒)。
There's a pretty simple solution for your problem:
When opening the page, store the userid and the current timestamp in some columns used for locking the element. On the page, include some JavaScript to call some script every minute that updates the timestamp - so as long as the user is on this page the timestamp will never be older than 1 minute. Simply prevent other people from editing the same element unless the timestamp is older than 1 minute (and a few seconds).
我知道这可能是一个较旧的问题,但您的问题的“最佳”答案可以在这里找到:
http://www.codeguru.com/forum/archive/index .php/t-372050.html
这是它的内容:
php.ini 文件包含一个名为 sesison.save_path 的设置,该设置确定 PHP 将包含会话数据的文件放置在何处。一旦会话变得陈旧,PHP 将在下一次垃圾收集期间将其删除。因此,对该会话的文件是否存在进行测试应该足以确定该会话是否仍然有效。
I know this might be a older question but the "best" answer to your question is found here:
http://www.codeguru.com/forum/archive/index.php/t-372050.html
Here is what it says:
The php.ini file contains a setting called sesison.save_path, this determines where PHP puts files which contain the session data. Once a session has become stale, it will be deleted by PHP during the next garbage collection. Hence, a test for the presence of a file for that session should be adequate to determine whether the session is still valid.