/    Sign up×
Community /Pin to ProfileBookmark

Session killing on window closing

Hi Everyone,

I am new to this forum and have a query. Might be it has already been asked earlier, but would be grateful if someone can guide or redirect me to it.

We are persisting the session (sesion ids) in the database when a user logs in. We have provided the Logoff button but there are high chances that our users may just close the window instead of the using the Log-off option. I need to close/kill the session (in the database) when the user closes the window.

Do we have any specific event for handling the close of the window. Is there any code snippet available to detect all the scenarios for closing of window.If yes, please share it with me.

Thanks a a lot to everyone.

With Best Regards,
Sampreet

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@chazzyJan 09.2006 — I don't have any snips but here's some advice, because I ran into the same dilemma not too long ago

  • - instead of killing the session when they close the window, what if you kill the session next time they login? would that satisfy the security requirement? (I'm assuming you have a 1 session per user requirement you're trying to fulfill)

  • - if you want to have something run on close, try some asynchronous requests that trigger on unload, these can send a request to the server to kill the session.
  • Copy linkTweet thisAlerts:
    @SelrachJan 09.2006 — Or you could have the client send a keep-alive request asyncronously, kill the session if the keep-alive doesn't come in a reasonable timeframe.
    Copy linkTweet thisAlerts:
    @sampreetauthorJan 18.2006 — Thanks Chazzy and Selrach for your replies.

    We are increasing the session timeout period for a userid for 2hrs. Session will get inactivated when inactiveity time period exceeds beyond 2hrs. The userid may be shared by one / more users but concurrent logins are not allowed (hence the session persistence in database). If the users log-off with the log-off buttons in the site, the session is closed normally and the users are able to log-in again. But if the user closes the browser using X button, then the session still remains active till the session timeout period completes. User will not be able to login in this period.

    We are considering the option give the user the choice to kill the session and start a fresh one on successful login attempt for the above mentioned situation.

    My undertanding with Javascript is onUnload() is called even when Window is minimized. Closing the session on onUnload could have serious repercussions. Please clarify if I am wrong or suggest suitable alternatives.

    Thanks again,

    Best regards,

    Sampreet
    Copy linkTweet thisAlerts:
    @KorJan 18.2006 — you may try [B]onbeforeunload[/B]. Works on FF since 1.04 version and in the last vesion of Mozilla as well (1.7.12)
    ×

    Success!

    Help @sampreet spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.1,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...