# Sharing Session Between Two Applications

**URL:** <https://www.ruby-forum.com/t/sharing-session-between-two-applications/96889>\
**Category:** Rails\
**Created:** [July 3, 2006, 7:22am UTC](https://www.ruby-forum.com/t/sharing-session-between-two-applications/96889 "2006-07-03T07:22:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajesh\_GS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5e9695/32.png) [@Rajesh\_GS](https://www.ruby-forum.com/u/Rajesh_GS)\
**Post date:** [July 3, 2006, 7:22am UTC](https://www.ruby-forum.com/t/sharing-session-between-two-applications/96889/1 "2006-07-03T07:22:50Z")

</div>

Hi

We have a rails application deployed and working fine. Along with this,  
we are planning to add “Opinion” forum. The url of the forum will be  
like [http://forum.mymainsite.com](http://forum.mymainsite.com) Is it possible to share the session  
(that is, if the user is already logged in on the main site, he need not  
log in again on the forum section).

Is it possible to add the ‘opinion’ as a child of the rails website, to  
keep the session.

thanks

=R

---

<div class="post-metadata">

**Author:** ![Rajesh\_GS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5e9695/32.png) [@Rajesh\_GS](https://www.ruby-forum.com/u/Rajesh_GS)\
**Post date:** [July 3, 2006, 7:50am UTC](https://www.ruby-forum.com/t/sharing-session-between-two-applications/96889/2 "2006-07-03T07:50:34Z")

</div>

On 7/2/06, Rajesh GS [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> keep the session.  
> I’m not sure how rails sets cookies. If it sets them for the whole  
> domain, and your forum runs on the same domain and sets cookies domain  
> wide also, then you should be able to share the cookie. As for the  
> session data it would probably work to share that, but of course your  
> forum would have to read/write to it in the correct format.

It would probably be easier to do it another way though. For example  
have a secret that your rails app and the forum both know, and when  
linking to the forum put the hashed secret in the query string and  
have that signify that the user is logged in. Or create an action in  
your rails app that verifies if a user is logged in, and have your  
forum do an http post to the verification url. Both of those are  
probably easier then trying to share the session data.

Chris

---

<div class="post-metadata">

**Author:** ![Rajesh\_GS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5e9695/32.png) [@Rajesh\_GS](https://www.ruby-forum.com/u/Rajesh_GS)\
**Post date:** [July 3, 2006, 8:02am UTC](https://www.ruby-forum.com/t/sharing-session-between-two-applications/96889/3 "2006-07-03T08:02:49Z")

</div>

On Jul 2, 2006, at 10:48 PM, snacktime wrote:

> > the user is already logged in on the main site, he need not log in  
> > session data it would probably work to share that, but of course your  
> > Chris  
> > Rajesh-

```
Set this in your config/environments/production.rb

```

ActionController::CgiRequest::DEFAULT\_SESSION\_OPTIONS.update  
( :session\_domain =\> ‘.mymainsite.com’)

-Ezra

---

<div class="post-metadata">

**Author:** ![Rajesh\_GS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/5e9695/32.png) [@Rajesh\_GS](https://www.ruby-forum.com/u/Rajesh_GS)\
**Post date:** [January 24, 2007, 4:12am UTC](https://www.ruby-forum.com/t/sharing-session-between-two-applications/96889/4 "2007-01-24T04:12:08Z")

</div>

Ezra Z. wrote:

> On Jul 2, 2006, at 10:48 PM, snacktime wrote:
> 
> > > the user is already logged in on the main site, he need not log in  
> > > session data it would probably work to share that, but of course your  
> > > Chris  
> > > Rajesh-
> 
> Set this in your config/environments/production.rb
> 
> ActionController::CgiRequest::DEFAULT\_SESSION\_OPTIONS.update  
> ( :session\_domain =\> ‘.mymainsite.com’)
> 
> -Ezra

I’d like to do what Rajesh was trying to do. The MySQL session store  
uses the session\_id column as the key for the session data. Does Rails  
use the same session\_id on both the main site and the forum site to  
access the MySQL session store?

Thanks.
