nibblebot Posted February 13, 2008 Share Posted February 13, 2008 I'm trying to end the sessions on my site when a user closes their UA. I have session.cookie_lifetime = 0 (the default). http://us3.php.net/manual/en/ref.session.php says: session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0. Shouldn't the cookie get deleted on browser close? As it stands it does not. I can provide other config variables if someone has an idea why this doesn't work. TIA, joshua. Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/ Share on other sites More sharing options...
laffin Posted February 13, 2008 Share Posted February 13, 2008 session_destroy() Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/#findComment-466236 Share on other sites More sharing options...
Orio Posted February 13, 2008 Share Posted February 13, 2008 I'm trying to end the sessions on my site when a user closes their UA. I have session.cookie_lifetime = 0 (the default). http://us3.php.net/manual/en/ref.session.php says: session.cookie_lifetime specifies the lifetime of the cookie in seconds which is sent to the browser. The value 0 means "until the browser is closed." Defaults to 0. Shouldn't the cookie get deleted on browser close? As it stands it does not. I can provide other config variables if someone has an idea why this doesn't work. TIA, joshua. Well, the browsers are supposed to delete the cookie when they close/leave the site. I don't really know ajax, but maybe you can run a script that will destroy the session every time the onClose event occurs? Orio. Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/#findComment-466239 Share on other sites More sharing options...
kts Posted February 13, 2008 Share Posted February 13, 2008 yeah, Orio is on to it, check into window.onClose and have it session_destroy Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/#findComment-466241 Share on other sites More sharing options...
revraz Posted February 13, 2008 Share Posted February 13, 2008 The session will end, as in if the user closed the browser and re-opened it, they would get a new session. But the session on the server side will remain until the GC runs. Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/#findComment-466248 Share on other sites More sharing options...
nibblebot Posted February 13, 2008 Author Share Posted February 13, 2008 The session will end, as in if the user closed the browser and re-opened it, they would get a new session. But the session on the server side will remain until the GC runs. This is the expected behavior. However, if I restart the browser, the cookie with the SID still remains. I'd prefer not to use any javascript to solve this. Do you think Firefox (the browser I'm testing with) refuses to delete the cookie? I have it set to delete cookie 'when it expires' in my Firefox settings. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/#findComment-466322 Share on other sites More sharing options...
revraz Posted February 13, 2008 Share Posted February 13, 2008 In your php.ini, are you setting cookies for sessions? Are you just using a normal session_start(); in your code? Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/#findComment-466327 Share on other sites More sharing options...
nibblebot Posted February 13, 2008 Author Share Posted February 13, 2008 In your php.ini, are you setting cookies for sessions? Yes. Are you just using a normal session_start(); in your code? Yes. Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/#findComment-466335 Share on other sites More sharing options...
laffin Posted February 13, 2008 Share Posted February 13, 2008 Just use a session_destroy in yer php code, when yer done with it. at the start of code, maybe ya can use a cookie, to dictate if there is an active session, if(isset($_COOKIE['us']) && !empty($_COOKIE['us'])) { $use_sessions=true; start_sessions(); } this will give ya use of the sessions, if that cookie is set when ya done with the session support setcookie('us',''); destroy_session(); now ya just need a place of when the cookie is set Quote Link to comment https://forums.phpfreaks.com/topic/90972-delete-session-cookie-on-browser-close/#findComment-466338 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.