Organizational Research By

Surprising Reserch Topic

destroy or unset session when user close the browser without clicking on logout


destroy or unset session when user close the browser without clicking on logout  using -'php,session'


  Possible Duplicate:
  How do I expire a PHP session after 30 minutes?  




I am destroying all session var in logout.php and calling it when user click on logout, what is user does not click on logout.php but directly close the browser. how can i delete session then???
    

asked Sep 24, 2015 by loknath.ganji
0 votes
2 views



Related Hot Questions

5 Answers

0 votes

You can set an expiration time for the session data, test it with each session_start call and destroy the session if it’s expired:

session_start();
if (!isset($_SESSION['EXPIRES']) || $_SESSION['EXPIRES'] < time()+3600) {
    session_destroy();
    $_SESSION = array();
}
$_SESSION['EXPIRES'] = time() + 3600;
answered Sep 24, 2015 by virendra.bajaj
0 votes

You cannot. However, session cookies are usually sent without an expire time which means they are deleted when the browser is closed, so the session is lost anyway.

answered Sep 24, 2015 by balvant maurya
0 votes

The session can be set to simply expire the server doesn't hear from the client after a certain period of time. That's the direction you want to be looking in...

Martin

answered Sep 24, 2015 by deepak
0 votes

PHP sessions should automatically expire when the browser window closes providing you do not modify the Session Cookies expiration time. If this is not happening then I would assume that you have modified this in some way and we would require further details to assist.

answered Sep 24, 2015 by 20shahi
0 votes

If you do not set an expire time for the session cookie, it will be deleted when the user closes the browser, which has the same effect for most practical purposes (unless you are worried about storage or security). If that is not good enough, you could set sessions to expire very quickly and periodically refresh them via AJAX.

answered Sep 24, 2015 by sanjaypal1983

...