Jump to content

Archived

This topic is now archived and is closed to further replies.

extrovertive

Destroying a session if user leaves a site?

Recommended Posts

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?

Share this post


Link to post
Share on other sites
You could check active sessions every 15 minutes (this would require a db with the active sessions) and delete the inactives.

Share this post


Link to post
Share on other sites
look at the onUnLoad function for Javascript

and have it just send a logout command to your login.php script, which I'm assuming you have
you're logout function on that script should destroy the session for you, if you have it written that way

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.