# How to expire session on window close

**URL:** <https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/126907>\
**Category:** Ruby\
**Created:** [January 23, 2008, 11:43am UTC](https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/126907 "2008-01-23T11:43:44Z")\
**Posts on this page:** 2\
**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, 11:43am UTC](https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/126907/1 "2008-01-23T11:43:44Z")

</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, 12:06pm UTC](https://www.ruby-forum.com/t/how-to-expire-session-on-window-close/126907/2 "2008-01-23T12:06:29Z")

</div>

On Jan 23, 10:43 am, Varun G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

This is more of a general web app development question, so you might  
get better answers in another group. That said, the short answer is  
that the session is expired when the session cookie is removed form  
the browser. Most browsers delete session cookies when the browser  
closes (not just a single window of that browser). It /may/ be  
possible to use some javascript to hook into a window close event and  
expire a specific cookie; but I wouldn’t know how off the top of my  
head, and it’s possible that it might not work across all browsers.

–  
Regards,

John W.
