简体   繁体   English

检查会话是否存在

[英]Check for existence of sessions

In my code I have a lot of sessions and I'm afraid that I could forget unset() some sessions. 在我的代码中,我有很多会话,但恐怕我会忘记unset()一些会话。 Any solution how I can check for existence sessions with ANY name? 有什么解决方案可以检查具有任何名称的存在会话吗? Ofc I can do that from server-side. 我可以从服务器端做到这一点。

All sessions are stored as keys in $_SESSION so loop through that is that what you mean ? 所有会话都作为键存储在$ _SESSION中,因此循环遍历意味着什么? or session_destroy() destroys all of the data associated with the current session. 或session_destroy()销毁与当前会话关联的所有数据。

If you mean, "how can see all the sessions", that would depend on the session storage mechanism used. 如果您的意思是“如何查看所有会话”,则取决于所使用的会话存储机制。 You might typically find file-based session data stored as individual files in /tmp (or more accurately, if session.save_handler is 'files', the path is set by session.save_path ) 通常,您可能会发现基于文件的会话数据存储为/ tmp中的单个文件(或更准确地说,如果session.save_handler是'files',则路径是由session.save_path设置的)

If you mean "how can I see all the variables in a session", you could use foreach 如果您的意思是“如何查看会话中的所有变量”,则可以使用foreach

foreach($_SESSION as $name=>$value)
{
     echo "$name = $value<br>";
}

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

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