Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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???

like image 343
nectar Avatar asked May 15 '10 11:05

nectar


2 Answers

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; 
like image 102
Gumbo Avatar answered Oct 27 '22 10:10

Gumbo


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.

like image 41
ThiefMaster Avatar answered Oct 27 '22 10:10

ThiefMaster