PHP会话超时过快 [英] PHP sessions timing out too quickly

查看:69
本文介绍了PHP会话超时过快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站上使用php Sessions,似乎它们以随机的间隔消失"了.我不知道它们是否由于不活动而超时或我的代码是否出了问题,但是有什么方法可以控制会话何时过期?

I'm using php Sessions on my website and it seems like they are "disappearing" at random intervals. I don't know if they are timing out due to inactivity or if something is wrong with my code, but is there some way to control the sessions of when they expire?

就像我可以在代码中放入内容还是在php.ini文件中更改内容一样?

Like can I put something in my code or change something in the php.ini file?

更新-因此,在这里进行更新,我切换了主机,魔术般地开始了会话.我不知道出了什么问题,但是显然他们不想正常工作.

Update- So just and update here, I switched hosts and magically the sessions started working. I have no clue what was wrong but apparently they did not want to work correctly.

推荐答案

随机到期是会话数据目录的经典症状,该会话数据目录由多个应用程序共享:session.gc_maxlifetime时间最短的会话很可能会从其他应用程序中删除数据.原因:

Random expiration is a classical symptom of session data directory shared by several applications: the one with the shortest session.gc_maxlifetime time is likely to remove data from other applications. The reason:

  1. 默认情况下,PHP将会话文件存储在系统临时目录中.
  2. 内置文件处理程序不跟踪谁拥有哪个会话文件(它仅将文件名与会话ID匹配):

  1. PHP stores session files in the system temporary directory by default.
  2. The builtin file handler doesn't track who owns what session file (it just matches file name with session ID):

我的建议是,为应用程序配置私有自定义会话目录.可以使用 session_save_path()函数或设置

My advice is that you configure a private custom session directory for your application. That can be done with the session_save_path() function or setting the session.save_path configuration directive. Please check your framework's documentation for the precise details on how to do it in your own codebase.

这篇关于PHP会话超时过快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆