deepPHP Posted June 19, 2013 Share Posted June 19, 2013 hi there, A PHP session destroyed when a user is ask for this(logout for instance) and when I closed my browser the session destroy. how the php session know if the browser closed or not and how this process have done. thank Quote Link to comment https://forums.phpfreaks.com/topic/279349-how-a-php-session-know-when-the-browser-closed/ Share on other sites More sharing options...
trq Posted June 19, 2013 Share Posted June 19, 2013 Session don't die when you close the browser, they expire after a period of inactivity. Quote Link to comment https://forums.phpfreaks.com/topic/279349-how-a-php-session-know-when-the-browser-closed/#findComment-1436815 Share on other sites More sharing options...
deepPHP Posted June 19, 2013 Author Share Posted June 19, 2013 Session don't die when you close the browser, they expire after a period of inactivity. so let me ask another question to understand that, how the web server checks if session is inactive?(time-stamp doesnt could solve that because it depends on exact specific time.. i mean i dont know how, but right after I close my browser all the sessions go away - is it happens in the client-side(browser) or the server-side?) thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/279349-how-a-php-session-know-when-the-browser-closed/#findComment-1436844 Share on other sites More sharing options...
Adam Posted June 19, 2013 Share Posted June 19, 2013 A user is linked to a session using a cookie. The cookie only contains a hash, which can be used to look up the file containing the serialized session data, generally in /tmp. When your browsers closes it will delete the cookie, therefore the user's session is lost. However the file in /tmp containing the actual session data will remain there until it's expired, and subsequently PHP has cleaned it up. Quote Link to comment https://forums.phpfreaks.com/topic/279349-how-a-php-session-know-when-the-browser-closed/#findComment-1436857 Share on other sites More sharing options...
kicken Posted June 19, 2013 Share Posted June 19, 2013 There are two parts to an active session: 1) A data file stored on the server containing all the variables and their values and 2) A cookie stored on your computer which identifies which datafile to use by means of a unique hash value. Because both parts are necessary for the session to work, a session can expire in one of two ways 1) Your browser forgets the cookie or 2) The server deletes the data file. When you close your browser, you are causing the expiration via option #1. Your browser will delete it's cookie containing the hash, thus breaking the reference to the data file and killing the session. The data file will remain on the server until it gets cleaned up later by an automated process. Option #2 happens if you stay idle for an extended period of time. On the server-side, all the session files are occasionally checked to see how old they are (based on last time of access). If they were last accessed more than a set amount of time ago, they are deleted. This is what causes the session to expire if you stop surfing the website for an extended period of time, but never actually close the browser. Quote Link to comment https://forums.phpfreaks.com/topic/279349-how-a-php-session-know-when-the-browser-closed/#findComment-1436861 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.