Organizational Research By

Surprising Reserch Topic

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


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 May 28, 2015 in PHP by rajesh
0 votes
42 views



Related Hot Questions

1 Answer

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 May 28, 2015 by rajesh

...