extrovertive Posted August 21, 2006 Share Posted August 21, 2006 I'm new with sessions.All I know with sesssions, the lifetime of it is based on the browser.However, let's say a user logged into my website (session is registered) and then leave my website. Well, the session is still valid. But I want it so that after they leave my site (not closing the browser), the session is destroy. How would I do this? Quote Link to comment https://forums.phpfreaks.com/topic/18166-destroying-a-session-if-user-leaves-a-site/ Share on other sites More sharing options...
poirot Posted August 21, 2006 Share Posted August 21, 2006 You could check active sessions every 15 minutes (this would require a db with the active sessions) and delete the inactives. Quote Link to comment https://forums.phpfreaks.com/topic/18166-destroying-a-session-if-user-leaves-a-site/#findComment-77932 Share on other sites More sharing options...
Zane Posted August 21, 2006 Share Posted August 21, 2006 look at the onUnLoad function for Javascriptand have it just send a logout command to your login.php script, which I'm assuming you haveyou're logout function on that script should destroy the session for you, if you have it written that way Quote Link to comment https://forums.phpfreaks.com/topic/18166-destroying-a-session-if-user-leaves-a-site/#findComment-77937 Share on other sites More sharing options...
Jenk Posted August 21, 2006 Share Posted August 21, 2006 there is no guaranteed method to ensure your session data is destroyed the moment a user leaves your site. Some users don't have JS enabled, some browsers don't have that function. It's easiest to just let PHP do the clean up after session.max_lifetime has expired. Quote Link to comment https://forums.phpfreaks.com/topic/18166-destroying-a-session-if-user-leaves-a-site/#findComment-77964 Share on other sites More sharing options...
yyboo Posted August 24, 2006 Share Posted August 24, 2006 [quote author=extrovertive link=topic=105022.msg419263#msg419263 date=1156137678]However, let's say a user logged into my website (session is registered) and then leave my website. Well, the session is still valid. But I want it so that after they leave my site (not closing the browser), the session is destroy. How would I do this?[/quote]I would REALLY like to know how you managed that as I have the opposite problem. My session kills every 24 minutes and I want the session to be hours long. Could you send me your session code so I can see maybe what I am doing wrong? I think my problem could be with the phpinfo() on my server but am not sure. Boy I wish I knew how you got it to keep a long session! Please let me know if possible your session code! Quote Link to comment https://forums.phpfreaks.com/topic/18166-destroying-a-session-if-user-leaves-a-site/#findComment-79975 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.