# Restore session from session\_id

**URL:** <https://www.ruby-forum.com/t/restore-session-from-session-id/118925>\
**Category:** Rails\
**Created:** [November 1, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/restore-session-from-session-id/118925 "2007-11-01T12:02:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [November 1, 2007, 12:02pm UTC](https://www.ruby-forum.com/t/restore-session-from-session-id/118925/1 "2007-11-01T12:02:38Z")

</div>

Hi all,

is it possible to get/restore a session by the session\_id in a  
controller action?

I’m using a flash component (MultiPowUpload) which unfortunately doesn’t  
pass cookies when calling an action. Therefore I have coded the  
session\_id into the called URL.

Now in the controller action I receive the session\_id as a param and  
want to check whether there is a corresponding session and read the user  
data.

Is there a way to do this??

Thanx,

Starburger

---

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [November 1, 2007, 5:00pm UTC](https://www.ruby-forum.com/t/restore-session-from-session-id/118925/2 "2007-11-01T17:00:35Z")

</div>

yes when you are implementing session then you can fetch the session id  
using session[:user] and compare it with the user id

---

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [November 1, 2007, 5:38pm UTC](https://www.ruby-forum.com/t/restore-session-from-session-id/118925/3 "2007-11-01T17:38:12Z")

</div>

On 1 Nov 2007, at 11:02, Star B. wrote:

> Now in the controller action I receive the session\_id as a param and  
> want to check whether there is a corresponding session and read the  
> user  
> data.
> 
> Is there a way to do this??

Rails can do it for you, however it’s been turned off recently. I  
forget the exact details, but it can definitely be done.

Fred

---

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [December 5, 2007, 11:39pm UTC](https://www.ruby-forum.com/t/restore-session-from-session-id/118925/4 "2007-12-05T23:39:08Z")

</div>

Hello Starburger,

I had a session cleaner that would look into session data before doing  
stuff. It worked like this:

```
CGI::Session::ActiveRecordStore::Session.find(:all, :conditions =>

```

[‘updated\_at \< ?’, cond]).each do |s|  
dataHash =  
CGI::Session::ActiveRecordStore::Session.unmarshal(s[:data])  
#  
User.find(dataHash[:rbac\_user\_id]).change\_online\_status(User::Offline)  
if dataHash[:rbac\_user\_id]  
@counter += 1  
end

So I was using this to check dead sessions out but it should work for  
you. If you have the session\_id you should be able to

s = CGI::Session::ActiveRecordStore::Session.find(params[session\_id])

dataHash =  
CGI::Session::ActiveRecordStore::Session.unmarshal(s[:data])

and then dataHash[:whatever\_you\_got\_in\_there]

Hope this helps.

I have a selfish motive here, I was wondering if you got this  
working. I’m looking to using the MultiPowUpload thing and need to  
know how to catch the file uploads.

Mike  
removed\_email\_address@domain.invalid

On Nov 1, 3:02 am, Star B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![starburger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/848f3c/32.png) [@starburger](https://www.ruby-forum.com/u/starburger)\
**Post date:** [November 2, 2007, 10:03am UTC](https://www.ruby-forum.com/t/restore-session-from-session-id/118925/5 "2007-11-02T10:03:01Z")

</div>

Dhaval P. wrote:

> yes when you are implementing session then you can fetch the session id  
> using session[:user] and compare it with the user id

The problem is, that the call doesn’t pass the session cookie - so there  
simply is no session object to compare. The only thing which is passed  
is the session\_id as a parameter.

So I need to access the session object based on the session\_id.
