您可以清除所有会话而不逐一进行吗? (模拟页面关闭)
首先,我对服务器端脚本相当陌生,所以我不知道这个问题是否有意义。
假设一个页面存储了 PHP、Perl 和 ASP 的会话。是否有一种快速简便的方法来模拟浏览器关闭并重新打开以立即重置/销毁/清除所有会话?或者是否必须对您单独使用的每种服务器语言进行会话清除?
Firstly, I am fairly new to server side scripting so I don't know if this question makes sense.
Suppose a page has stored sessions for PHP, Perl and ASP. Is there a quick and easy way to emulate the browser being closed and re-opened to reset/destroy/clear all the sessions at once? Or would one have to go through the session clearing for every server language you used individually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的意思是关闭浏览器,则
session_destroy
听起来像是你的票。如果您的意思是销毁所有会话,那就有点不同了;关闭浏览器不会破坏所有会话,除非所有用户都关闭了浏览器。一般来说,每个浏览器/用户都有一个会话。
执行此操作取决于您的会话的实施方式。通常 PHP 将会话信息存储在文件中...因此,如果您找出包含会话文件的目录,然后使用 rm -R * 或类似的东西清除它...应该可以窍门。在执行此操作之前,请务必检查该目录中是否只有 PHP 会话文件;)
您还可以使用
session_set_save_handler
和其他类似的方法。如果您执行了类似的操作,您可以更好地控制清除所有会话(并且它将帮助您处理暴露的会话数据)If you mean close the browser, then
session_destroy
sounds like your ticket.If you mean destroy all sessions it's a little different; closing the browser wouldn't destroy all sessions unless all users closed their browsers. Generally speaking, every browser/user has one session.
Doing this depends on how your sessions are implemented. Typically PHP stored session info in files... so if you figured out which directory contained the session files, and just cleared it with a
rm -R *
or something of the like... that should do the trick. Be sure to check that there are only PHP session files in that directory before you do it though ;)You could also set up a PHP script to use sessions in a MySQL database (or any other medium you want) using
session_set_save_handler
and other methods like it. If you did something like this, you could have more control over clearing all sessions (and it would help you deal with exposed session data)在 ASP.NET 中,您可以使用
Session.Abandon
来销毁存储在 Session 对象中的所有对象并释放其资源。In ASP.NET you have
Session.Abandon
which destroys all the objects stored in a Session object and releases their resources.