can you clear all sessions without going through each individual one? (emulate the page closing)
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 re开发者_如何学Cset/destroy/clear all the sessions at once? Or would one have to go through the session clearing for every server language you used individually?
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)
In ASP.NET you have Session.Abandon
which destroys all the objects stored in a Session object and releases their resources.
精彩评论