# Session Expiration Problem: How to keep a user logged in for

**URL:** <https://www.ruby-forum.com/t/session-expiration-problem-how-to-keep-a-user-logged-in-for/109132>\
**Category:** Rails\
**Created:** [July 11, 2007, 7:07pm UTC](https://www.ruby-forum.com/t/session-expiration-problem-how-to-keep-a-user-logged-in-for/109132 "2007-07-11T19:07:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [July 11, 2007, 7:07pm UTC](https://www.ruby-forum.com/t/session-expiration-problem-how-to-keep-a-user-logged-in-for/109132/1 "2007-07-11T19:07:41Z")

</div>

How do I keep the Rails session from expiring when the browser exits? I  
would ideally like the user to be logged for a few days (e.g. 2 weeks).

Do I use the Rails “session” or “cookies”? Also, my understanding is  
that session[:session\_expires] doesn’t work.

Thanks.

---

<div class="post-metadata">

**Author:** ![thabenksta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/97f17d/32.png) [@thabenksta](https://www.ruby-forum.com/u/thabenksta)\
**Post date:** [July 11, 2007, 7:51pm UTC](https://www.ruby-forum.com/t/session-expiration-problem-how-to-keep-a-user-logged-in-for/109132/2 "2007-07-11T19:51:09Z")

</div>

On 11 Jul 2007, at 19:07, Ben K. wrote:

> How do I keep the Rails session from expiring when the browser  
> exits? I  
> would ideally like the user to be logged for a few days (e.g. 2  
> weeks).
> 
> Do I use the Rails “session” or “cookies”? Also, my understanding is  
> that session[:session\_expires] doesn’t work.

You need to use a cookie and use that to log the user in  
automatically. You can then set the cookie to expire after 2 days, 2  
weeks, 2 months, …

It’s part of acts as authenticated and restful authentication, but  
here’s a page describing the way to do it yourself:  
[http://technoweenie.stikipad.com/plugins/show/Remember+Me](http://technoweenie.stikipad.com/plugins/show/Remember+Me)

Best regards

Peter De Berdt
