# How to expire session on window close

**URL:** <https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/196580>\
**Category:** Rails\
**Created:** [January 23, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/196580 "2008-01-23T12:30:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![varunkumargoel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@varunkumargoel](https://www.ruby-forum.com/u/varunkumargoel)\
**Post date:** [January 23, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/196580/1 "2008-01-23T12:30:12Z")

</div>

Hi all,  
I created one login page using LDAP server authentication now when  
i have logged into the system and without logout i just closed the  
window and when i again come and open the window it’s come as log in.  
But it should not show as already login.  
Please tell me that how can i expire session on window close.  
Thanks & regards  
Varun G.

---

<div class="post-metadata">

**Author:** ![varunkumargoel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@varunkumargoel](https://www.ruby-forum.com/u/varunkumargoel)\
**Post date:** [January 23, 2008, 2:24pm UTC](https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/196580/2 "2008-01-23T14:24:57Z")

</div>

On 23 Jan 2008, at 11:30, Varun G. wrote:

> Hi all,  
> I created one login page using LDAP server authentication now  
> when  
> i have logged into the system and without logout i just closed the  
> window and when i again come and open the window it’s come as log in.  
> But it should not show as already login.  
> Please tell me that how can i expire session on window close.

You can’t do this 100% reliably. You could try an ajax request from  
onClose that would log the user out (but of course that will cause  
problems if the user has 2 windows open and closes 1).

Fred

---

<div class="post-metadata">

**Author:** ![varunkumargoel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/ed8c4c/32.png) [@varunkumargoel](https://www.ruby-forum.com/u/varunkumargoel)\
**Post date:** [January 23, 2008, 5:28pm UTC](https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/196580/3 "2008-01-23T17:28:48Z")

</div>

“Varun G.” writes:

> Hi all,  
> I created one login page using LDAP server authentication now when  
> i have logged into the system and without logout i just closed the  
> window and when i again come and open the window it’s come as log in.  
> But it should not show as already login.  
> Please tell me that how can i expire session on window close.

We faced the same issue on [FATdrive.tv](http://FATdrive.tv) plus we also want to have a  
single sign on per account.

Our solution is to log the sign in user and monitor for extended period  
of inactivity. If the  
threshold is reached we force the session to expire and expires the log  
entry (either delete or  
change its status).

If the user signs out everything is fine. In the case that he doesn’t we  
check for an open session  
(log entry) at next login. If an entry is found we expire it and create  
a new one. This is because  
the user may be trying to login a second time or they had not logged out  
previously.

Basically, we employ both Rails session and our log entry  
(OnlineSession) to manage user sessions.  
Though, the bulk of the work is done in OnlineSession.

Hope this help point you in the right direction.

– Long  
[http://FATdrive.tv/wall/trakb/10-Long](http://FATdrive.tv/wall/trakb/10-Long)  
[http://FATdrive.tv/](http://FATdrive.tv/) - store, play and share
