omelette Posted August 9, 2006 Share Posted August 9, 2006 Does anyone have any idea why my session doesn't seem to be ending properly when I close my browser? Could it be to do with the php settings?I checked the session ID then closed and reopened the browser and the session ID was the same! Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/ Share on other sites More sharing options...
dual_alliance Posted August 9, 2006 Share Posted August 9, 2006 Have a logout page which will cancel your session.E.g[code=php:0]<?phpsession_start();if(!isset($_REQUEST['logmeout'])){ session_unset(); session_destroy(); if(!session_is_registered('username')){ echo "<center><font color=red><strong>You are now logged out!</strong></font></center><br />"; echo "<center><strong>Login:</strong></center><br />"; include 'index.php'; }}?>[/code]Hope this helps,dual_alliance Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-71922 Share on other sites More sharing options...
bltesar Posted August 9, 2006 Share Posted August 9, 2006 logouts work, but you cannot rely on users to logout and you still have the problem of what to do when a browser is closed without logging out.sessions should be lost when the browser is closed, although they do persist on the server until automatic cleanup gets rid of them. They can only be reaccessed if there is some memory of the session id, say in a cookie, and specific code to reopen the session.how are the sessions being started?try creating a session variable with some value, close your browser, reopen it and see if the stored value is also retained. Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-71923 Share on other sites More sharing options...
onlyican Posted August 9, 2006 Share Posted August 9, 2006 Are you closing all instances of the browserFor example, using FireFoxClosing that website does not always end the session (well not straight away)Whereas closing FireFox (all instances) should Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-71928 Share on other sites More sharing options...
omelette Posted August 9, 2006 Author Share Posted August 9, 2006 I am closing all instances of the browser, I am using Internet Explorer.I created a session variable and when i close and reopen the browser, the value in the variable is retained.I am starting the sessions on every page with session_start().Would the session.cookie_lifetime have anything to do with the problem? It is set to 3600 and i think the default is 0. Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-71937 Share on other sites More sharing options...
bltesar Posted August 9, 2006 Share Posted August 9, 2006 that must be it see http://us2.php.net/manual/en/ref.session.php#ini.session.cookie-lifetime Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-71944 Share on other sites More sharing options...
omelette Posted August 9, 2006 Author Share Posted August 9, 2006 Yeah, i think that probably is the problem now, just don't know how to solve it!I haven't got access to php.ini so need to know if there is another way to change this setting to 0 as i think it may be causing other problems. Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-72047 Share on other sites More sharing options...
bltesar Posted August 9, 2006 Share Posted August 9, 2006 you can change the parameter for the duration of your script using session_set_cookie_paramssee http://us2.php.net/manual/en/function.session-set-cookie-params.php Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-72061 Share on other sites More sharing options...
omelette Posted August 9, 2006 Author Share Posted August 9, 2006 I have tried putting:session_set_cookie_params(0);on every page before session_start but this is not having any effect. Am I using it properly? Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-72067 Share on other sites More sharing options...
bltesar Posted August 10, 2006 Share Posted August 10, 2006 I've never used it before, but I tested it out and it seems to work.try this[code]$params=session_get_cookie_params();print_r($params); [/code]to see if the operation is actually working. Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-72208 Share on other sites More sharing options...
omelette Posted August 10, 2006 Author Share Posted August 10, 2006 thanks, it seems to work now, not sure why it didn't do anything before.the only problem is that by setting the cookie parameters to 0, whenever the browser is refreshed, the session is lost so the session doesn't work! i wanted the session to end only when the browser closes, not when it is refreshed.any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-72332 Share on other sites More sharing options...
bltesar Posted August 11, 2006 Share Posted August 11, 2006 That doesn't make sense. I've not had such behavior with refreshes. Perhaps it is due to the settings on your browser. Quote Link to comment https://forums.phpfreaks.com/topic/17037-session-not-ending/#findComment-72833 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.