Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Share session between subdomains

#4818

Sessions cookies don't hace domain, so by default navigators use current HTTP_HOSTS.

If you want to share session between www.example.com and username.example.com you can't.

The next patch resolve this problem by adding a domain option in session_store initializar.

The syntax is:

  Rails.application.config.session_store :cookie_store, :key => '_app_session', :domain => :all

Reported by Guillermo Álvarez · June 10th, 2010 @ 10:58 AM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Guillermo Álvarez
  2. Guillermo Álvarez
    Guillermo Álvarez

    This patch is so simple, and just cover most of the cases i know, so for most complicated cases like 3th level domain, you must be explicit. For example:

    If you want to share session between *.google.co.uk you do:

      Rails.application.config.session_store :cookie_store, :key => '_app_session', :domain => ".google.co.uk"
    

    June 10th, 2010 @ 11:25 AM

  3. Guillermo Álvarez
    Guillermo Álvarez
    • Tag changed from cookie_store, session_store.rb to 3.x, cookie_store, session_store.rb

    June 10th, 2010 @ 03:23 PM

  4. Repository
    Repository
    • State changed from new to resolved

    (from [c4d6245e875bbb276c122a5a401422d341dac4df]) Add support for multi-subdomain session by setting cookie host in session cookie so you can share session between www.example.com, example.com and user.example.com. [#4818 Share session between subdomains state:resolved]

    Signed-off-by: David Heinemeier Hansson david@loudthinking.com
    http://github.com/rails/rails/commit/c4d6245e875bbb276c122a5a401422...

    June 10th, 2010 @ 05:05 PM

  5. Repository
    Repository

    (from [330a89072a493aafef1e07c3558964477f85adf0]) Revert "Add support for multi-subdomain session by setting cookie host in session cookie so you can share session between www.example.com, example.com and user.example.com. [#4818 Share session between subdomains state:resolved]"

    It does not work for domains like co.uk and com.br.

    This reverts commit c4d6245e875bbb276c122a5a401422d341dac4df.
    http://github.com/rails/rails/commit/330a89072a493aafef1e07c3558964...

    June 10th, 2010 @ 07:08 PM

  6. Rizwan Reza
    Rizwan Reza

    (from [44830ead1c88e1c45124133ce3e2ed9f890f42de]) Add support for multi-subdomain session by setting cookie host in session cookie so you can share session between www.example.com, example.com and user.example.com. [#4818 Share session between subdomains state:resolved]

    This reverts commit 330a89072a493aafef1e07c3558964477f85adf0.
    http://github.com/rails/rails/commit/44830ead1c88e1c45124133ce3e2ed...

    June 11th, 2010 @ 03:36 PM

  7. Bryce Thornton
    Bryce Thornton

    I really like this new ":domain => :all" option, but I'm getting a "ActionController::InvalidAuthenticityToken" exception when trying to use it. Everything works fine when specifying the domain directly.

    June 19th, 2010 @ 08:44 PM

  8. iGEL
    iGEL

    Here is a list of all domains with several levels (like .co.uk): http://publicsuffix.org/ It's maintained by the Mozilla Project.

    September 7th, 2010 @ 07:35 PM

  9. Fjan
    Fjan

    This patch doe produce a cookie that doesn't conform to specs if the host you are accessing is "localhost" or an IP address. The browsers I tried don't seem to care about this but Unix' wget will complain about it.

    December 2nd, 2010 @ 04:34 PM