Domain Session in Rails 4

I have a problem with the desire to use a session through domains (rather than a subdomain). For example, I have .co.uk, .com.au and .com all at the same address.

I know that for subdomains I can use something like:

SomeApp::Application.config.session_store :cookie_store, key: '_some_app_session', domain => :all, :tld_length => 2

But I would like my solution to work between the actual domains in order to have one set of sessions / cookies.

+4
source share
2 answers

Since the default session store is cookie_store

You can simply do this as if you could send an email token with an authentication token. Make sure the cookie is correct on example.org and, if so, redirect them to:

http://example.com?token= , , , . , cookie example.com, .

, ( cookie) , .

, , - . example.org, - :

before_filter :redirect_to_dot_com
...
def redirect_to_dot_com
  url = "http://example.com" + request.fullpath
  url= destination + (url.include?('?') ? '&' : '?') + "token=#{current_user.token}" if signed_in?
  redirect_to url, status: 301
end

, .org.

(Ruby on Rails)

+1

PHP, ?php=bad :get, . URL- .

session[:edition_id] = 'UK' :

cookies[:edition_id] = { value: 'UK', domain: 'some-app.com', expires: 1.year.from_now } 

# or if you want to be google 10.years.from_now

session[:edition_id] = 'UK', cookie _myapp_session. , , .

cookie , , get .

+1

All Articles