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 29, 2015 by sachin wagh
0 votes

Related Hot Questions

5 Answers

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 29, 2015 by ashishshukla
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:

if (!isset($_SESSION['EXPIRES']) || $_SESSION['EXPIRES'] < time()+3600) {
    $_SESSION = array();
$_SESSION['EXPIRES'] = time() + 3600;
answered Sep 29, 2015 by kotmus2002
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 29, 2015 by pradip.bhoge
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 29, 2015 by sandeep bhadauria
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...


answered Sep 29, 2015 by patelnikul321