简体   繁体   English

在ajax请求中处理session_regenerate_id()

[英]Handling session_regenerate_id() in ajax requests

I want to secure a little bit my application, especially I want to improve the way how sessions are handled. 我想保护一点我的应用程序,特别是我想改进会话的处理方式。 So, at this moment I know several facts: 所以,此刻我知道几个事实:

  1. session_regenerate_id(false) does not destroy old session session_regenerate_id(false)不会破坏旧会话
  2. session_regenerate_id(true) destroys old session. session_regenerate_id(true)销毁旧会话。 With ordinary page reloads there is nothing wrong with using session_regenerate_id(true) . 使用普通页面重新加载使用session_regenerate_id(true)没有任何问题。

However when making dozens concurrent AJAX requests there may be a problem which results in an error message object destruction failed . 但是,在进行数十个并发 AJAX请求时,可能会出现导致错误消息object destruction failed

So, there is nothing left to do, then to use session_regenerate_id(false) in AJAX request. 因此,没有什么可做的,然后在AJAX请求中使用session_regenerate_id(false)

But what is needed, is to somehow mark previous outdated sessions, which become outdated as a result of invoking session_regenerate_id(false) , as "zombie" sessions that will somehow be destroyed and not litter the sessions folder. 但是,需要的是以某种方式标记先前过时的会话,这些会话由于调用session_regenerate_id(false)而变得过时,因为“僵尸”会话将以某种方式被破坏而不会丢失会话文件夹。

I need some practical advice on how to implement this. 我需要一些关于如何实现这一点的实用建议。

All session cleanup, including those with regenerated IDs, is handled by PHP's session garbage collector. 所有会话清理(包括具有重新生成的ID的清理)都由PHP的会话垃圾收集器处理。 There is nothing special needed when calling session_regenerate_id(false) to remove old sessions from storage. 调用session_regenerate_id(false)从存储中删除旧会话时,没有什么特别需要。

PHP's settings for session.gc_probability , session.gc_divisor , and session.gc_maxlifetime apply. 适用于session.gc_probabilitysession.gc_divisorsession.gc_maxlifetime PHP设置

You can also run your own session storage cleanup based on last access time . 您还可以根据上次访问时间运行自己的会话存储清理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM