# session question - unique identifier in cookie store?

**URL:** <https://discuss.rubyonrails.org/t/session-question-unique-identifier-in-cookie-store/29863>\
**Category:** rubyonrails-talk\
**Created:** [May 27, 2008, 3:00pm UTC](https://discuss.rubyonrails.org/t/session-question-unique-identifier-in-cookie-store/29863 "2008-05-27T15:00:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean\_O\_Hara](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@Sean\_O\_Hara](https://discuss.rubyonrails.org/u/Sean_O_Hara)\
**Post date:** [May 27, 2008, 3:00pm UTC](https://discuss.rubyonrails.org/t/session-question-unique-identifier-in-cookie-store/29863/1 "2008-05-27T15:00:15Z")

</div>

Hi,

I recently switched to the cookie session store for my rails app, and I am wondering how I can access some kind of unique identifier for each session between requests. It used to be (when I was using active record store) that the session id was set and that string didn’t change between requests. Now, of course, the session id does change between requests because that is where the session data is stored. However, rails must be setting some unique identifier in this encrypted string, otherwise there wouldn’t be any session tracking. How can I access such a unique identifier? I realize I get just set a variable, but it seems pointless to redo something that is already being handled by rails.

FYI, I was using the session\_id to track the number of plays of a given song on my site, in order to know how many times a song was played by a unique user I track their session id in the database.

Thanks for any info.

Sean

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [May 27, 2008, 5:16pm UTC](https://discuss.rubyonrails.org/t/session-question-unique-identifier-in-cookie-store/29863/2 "2008-05-27T17:16:29Z")

</div>

> Hi,
> 
> I recently switched to the cookie session store for my rails app,  
> and I am wondering how I can access some kind of unique identifier  
> for each session between requests. It used to be (when I was using  
> active record store) that the session id was set and that string  
> didn't change between requests. Now, of course, the session id does  
> change between requests because that is where the session data is  
> stored. However, rails must be setting some unique identifier in  
> this encrypted string, otherwise there wouldn't be any session  
> tracking. How can I access such a unique identifier? I realize I get  
> just set a variable, but it seems pointless to redo something that  
> is already being handled by rails.

The point of the session\_id was to connect a user to a row in the  
database with session info (or file on disk etc...) This isn't needed  
with the cookie store, (since the cookie is the store) and so I don't  
think there is one. You could probably add one in yourself.

The data isn't actually encrypted: it's just base 64 encode marshaled  
data (with a cryptographic hash). You can see the entire session by  
taking the first bit of the cookie (before the --) and run it through  
Marshal.load(string.unpack('m').first)

Fred
