获取所有 PHP session_id 的列表
无法获取 PHP SESSIONS 中所有 session_id
的列表吗?
笔记: 我需要在服务器中维护一些文件。一个文件等于一个会话。如果会话过期,我需要确定旧文件的行为。
谢谢大家的建议。
Is't possible to get list of all session_id
in PHP SESSIONS?
Note:
I need maintained some file in the server. One file equal one session. And I need to determine behaviour of old files if SESSION expire.
Thank you all for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如其他人所回答的,会话存储在 php.ini 中由
session.save_path
定义的路径中,您可以迭代此目录以检索每个会话的列表。替代方法是更改会话存储并使用
session_set_save_handler()
。您可以将所有会话存储在数据库中,并按照您的意愿使用它。As others have answered, sessions are stored in the path defined by
session.save_path
inphp.ini
and you can iterate this directory to retrieve a list of every session.An alternative approach would be to change the session storage and move it to a database using
session_set_save_handler()
. You could store all your sessions in a database and do with it whatever you wish.要获取所有现有会话 ID 的列表,您可以做的最好的事情是:
但这不会告诉您哪些文件仍然有效。我不太明白你问题的第二部分。但可以手动反序列化它们以探测属性。
The best you can do to get a list of all existing session IDs is:
But that won't tell you which files are still valid. And I don't really get the second part of your question. But it is possible to unserialize them manually to probe for attributes.
我想在一个旧项目中这样做。
我用 session_id 命名文件(类似于:sessionid_some_file.tmp):
_TMP_PATH_:要检查的文件所在的路径。
foreach 文件我得到了 session_id,打开它并测试里面是否有东西。 (我在每个会话打开后都写了一些东西)
但是要小心,这段代码从未在生产环境中出现过。
i'd to do this in an old project.
i named the files with the session_id (something like this: sessionid_some_file.tmp) :
_TMP_PATH_ : path where the files to check are.
foreach files i get the session_id, open it and test if something inside. (i wrote something after each session opened)
But be carefull, this piece of code has never been in a production environnment.