# Session ID too long

**URL:** <https://www.ruby-forum.com/t/session-id-too-long/167201>\
**Category:** Rails\
**Created:** [May 5, 2009, 1:55pm UTC](https://www.ruby-forum.com/t/session-id-too-long/167201 "2009-05-05T13:55:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cesardiaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@cesardiaz](https://www.ruby-forum.com/u/cesardiaz)\
**Post date:** [May 5, 2009, 1:55pm UTC](https://www.ruby-forum.com/t/session-id-too-long/167201/1 "2009-05-05T13:55:44Z")

</div>

Hi,

I have a problem with the Session ID in my Rails application. I need to  
store some data of anonymous users and then, when the session expires,  
delete that information from de database.

I have a filter in some point of my application when I try to create an  
anonymous user which I want to identify by its session\_id. I read that  
this session\_id must be a 32 char length value, but, when I run the  
application my session\_id value is:

BAh7CToMY3NyZl9pZCIlYmE1ZWYxNzY3MzUwMjI2MzU0NWFhMWUxODZkZDY4M2U6EXNlYXJjaFN0cmluZyIJbmFkYToPdXBkYXRlZF9hdEl1OglUaW1lDatQG4BQk5jZBjofQG1hcnNoYWxfd2l0aF91dGNfY29lcmNpb25GIgpmbGFzaElDOidBY3Rpb25Db250cm9sbGVyOjpGbGFzaDo6Rmxhc2hIYXNoewAGOgpAdXNlZHsA–206695460a9e840bd0393690e0d8813ee46ce434

The code is:

def save\_anonymus\_user  
self.current\_user = User.new(:login =\> “guest” +  
session.session\_id,  
:password =\> “guest”, :confirm\_password =\> “guest”, :session\_id  
=\> session.session\_id)  
end

And when the session expires, I am using the session\_lifetime plugin to  
make some stuff like deleting the user from the database.

expires\_session :time =\> 5.minutes, :redirect\_to =\> ‘/’, :on\_expiry =\>  
lambda {  
user = User.find\_by\_session\_id(session.session\_id)  
User.delete(user.id) unless user.nil?  
}

At this point, the session\_id is a 32 char length value, as expected.

What is wrong with the session at the first point? I am lost.

Thanks!

---

<div class="post-metadata">

**Author:** ![cesardiaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@cesardiaz](https://www.ruby-forum.com/u/cesardiaz)\
**Post date:** [May 5, 2009, 2:29pm UTC](https://www.ruby-forum.com/t/session-id-too-long/167201/2 "2009-05-05T14:29:40Z")

</div>

Yeah I got that problem too and I just alter the column to be varchar  
(500) ☹

On May 5, 9:55 pm, César Díaz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![cesardiaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@cesardiaz](https://www.ruby-forum.com/u/cesardiaz)\
**Post date:** [May 5, 2009, 2:30pm UTC](https://www.ruby-forum.com/t/session-id-too-long/167201/3 "2009-05-05T14:30:51Z")

</div>

Why aren’t you guys using the cookie session store?

- 

Maurício Linhares  
[http://alinhavado.wordpress.com/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)

---

<div class="post-metadata">

**Author:** ![cesardiaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@cesardiaz](https://www.ruby-forum.com/u/cesardiaz)\
**Post date:** [May 5, 2009, 2:32pm UTC](https://www.ruby-forum.com/t/session-id-too-long/167201/4 "2009-05-05T14:32:02Z")

</div>

hey, unless yr storing the session in the db for some business  
requirement  
you might want to try out using the cookie session store that rails uses  
by  
default. it’s a definite improvement over maintaining it yourself and  
having  
to sweep out behind old expired sessions.

RSL

---

<div class="post-metadata">

**Author:** ![cesardiaz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/dfb087/32.png) [@cesardiaz](https://www.ruby-forum.com/u/cesardiaz)\
**Post date:** [May 5, 2009, 6:36pm UTC](https://www.ruby-forum.com/t/session-id-too-long/167201/5 "2009-05-05T18:36:27Z")

</div>

Ok, I think that you are not understanding me or I am not understanding  
you. My problem is not that I want to store the session in the database  
or that the field for session id is too short.

I need the session\_id because I want to have anonymous users in my  
application. These anonymous users will have data in the database if  
they do some operations through the front-end of the application, but  
when these users had gone and their session expire, I want to delete the  
data that I have stored from them. So, in the moment of the session  
expiration, I think that I only can to access to the session\_id, and  
that is because I decide to identify the users with the session\_id that  
they are relationed to.

That is my intention, but I don’t know if it is possible.

Any ideas?
