daydreamer Posted November 21, 2008 Share Posted November 21, 2008 Hi. On a member site I am making how would I automatically destroy a session after 20 minutes of no use? At the moment I don't think the session gets destroyed if the user does not log out. Thanks Link to comment https://forums.phpfreaks.com/topic/133576-session_destroy-automatically/ Share on other sites More sharing options...
trq Posted November 21, 2008 Share Posted November 21, 2008 20 minutes is normally the default. It should happen automatically. Link to comment https://forums.phpfreaks.com/topic/133576-session_destroy-automatically/#findComment-694813 Share on other sites More sharing options...
dezkit Posted November 21, 2008 Share Posted November 21, 2008 php.ini Link to comment https://forums.phpfreaks.com/topic/133576-session_destroy-automatically/#findComment-694816 Share on other sites More sharing options...
PFMaBiSmAd Posted November 21, 2008 Share Posted November 21, 2008 A session is just a container. Don't rely on the destruction of a session to log someone out. Store the last access time for each visitor in your user table and on each page request test if the last access time is farther in the past than a limit you set and take appropriate action if it is, such as setting the value that says they are logged out. Session garbage collection is not intended to end sessions or log someone out. It runs based on probability and unless you change the settings to cause it to run on each session_start, you cannot guarantee when old session data files will be deleted. Link to comment https://forums.phpfreaks.com/topic/133576-session_destroy-automatically/#findComment-694817 Share on other sites More sharing options...
daydreamer Posted November 21, 2008 Author Share Posted November 21, 2008 Ok, I was doing this on each page if ($_SESSION['in'] == true) { //user logged in } and then to log out session_unset(); session_destroy(); are you saying to logout I should be doing this (also if the users been inactive for a while) $_SESSION['in']=false; Link to comment https://forums.phpfreaks.com/topic/133576-session_destroy-automatically/#findComment-694833 Share on other sites More sharing options...
revraz Posted November 21, 2008 Share Posted November 21, 2008 No, you should do session_start(); session_destroy(); Link to comment https://forums.phpfreaks.com/topic/133576-session_destroy-automatically/#findComment-694837 Share on other sites More sharing options...
daydreamer Posted November 21, 2008 Author Share Posted November 21, 2008 yeh i do as without session_start(); it wouldn't work. I thought that was assumed, cheers tho. Link to comment https://forums.phpfreaks.com/topic/133576-session_destroy-automatically/#findComment-694841 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.