Jump to content


Photo

Destroying a session if user leaves a site?


  • Please log in to reply
4 replies to this topic

#1 extrovertive

extrovertive
  • Members
  • PipPipPip
  • Advanced Member
  • 235 posts

Posted 21 August 2006 - 05:21 AM

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?

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 21 August 2006 - 08:02 AM

You could check active sessions every 15 minutes (this would require a db with the active sessions) and delete the inactives.
~ D Kuang

#3 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 21 August 2006 - 08:36 AM

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

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#4 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 21 August 2006 - 09:51 AM

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.

#5 yyboo

yyboo
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationFlorida

Posted 24 August 2006 - 06:44 PM

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?


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!
-----------------------------
www.mommatown.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users