2

I am building a Rails app that will live in the subdomain of a Symfony 2 app (PHP). They will be used by the same type of users, and so we want them to go back and forth between the apps and ideally only login once.

I've seen some solutions on how to share session between subdomains for the same kind of apps, but no solution for sharing session between Symfony and Rails. Is it possible?

I was particularly intrigued that Rails session_store can use a database backend -- the default is cookie. That makes me wonder if both apps were to use the database backend, would they be able to share the sessions?

What other alternatives can I use to make this work, if it can work?

Community
  • 1
  • 1
picardo
  • 24,530
  • 33
  • 104
  • 151

1 Answers1

3

Sure it is possible, but I don't know how much work you have to put in ;)

The main thing is the Session ID. It all depends on that. You must make both applications use the same session storage, else it's impossible.

It doesn't matter if you store the SessionId in a database, in a file (would be pretty slow) or somewhere else, as long as both applications use it.

As you mentioned, Rails supports sessions inside a database out of the box. There's also another way in Rails: Memchached Storage. It's more or less an own database, which is optimized for fast key-value lookups.

So you should look if there's a Symfony plugin that supports either SessionId in database or in a Memcache Storage.

Have a look here: http://watsonbox.github.com/blog/2012/05/01/sharing-session-between-rails-and-php/


Forgot to mention: Both applications must also use the same SESSION_ID name inside the cookie ;)

Benjamin M
  • 23,599
  • 32
  • 121
  • 201