Sharing sessions between subdomains?


#1

Hello,

I know how to share sessions between subdomains in PHP. Can anyone
please guide me as to how I can share sessions using Ruby? Where can I
set the value of domain for which the cookie is set?

I would like for a user to login on the home page and then go to 

blog.home.com and not have to login again.

Any guidance/pointers are appreciated.

Thanks'
Frank

#2

softwareengineer 99 wrote:

Hello,

I know how to share sessions between subdomains in PHP. Can anyone
please guide me as to how I can share sessions using Ruby? Where can I
set the value of domain for which the cookie is set?

I would like for a user to login on the home page and then go to 

blog.home.com and not have to login again.

Any guidance/pointers are appreciated.

Thanks'
Frank

Isn’t that just a matter of how you have your cookie set?

Instead of setting the domain of the cookie to ‘blog.home.com’ just set
it to ‘.home.com’ and then that cookie should be valid for any host
under the ‘home.com’ domain.


#3

sach wrote:

Any guidance/pointers are appreciated.

Thanks'
Frank

Isn’t that just a matter of how you have your cookie set?

Instead of setting the domain of the cookie to ‘blog.home.com’ just set
it to ‘.home.com’ and then that cookie should be valid for any host
under the ‘home.com’ domain.

I believe the question was ‘how’… The answer is here:

http://api.rubyonrails.com/classes/ActionController/Cookies.html


#4

Thanks Alex for your reply.

Should the cookies be set in application.rb? I tried using
cookies[:domain]=‘domain.com’ but got an “undefined variable” error?

Where should this setting for cookies be set if I want it to be
applied on a application wide level?

I also tried my controller file but to no avail?

Then I placed the cookie settings in environment.rb. I don’t get an
error but the session isn’t recognized on the subdomain?

I appreciate your assistance very much.

Thanks
Frank

Alex Y. removed_email_address@domain.invalid wrote:

I believe the question was ‘how’… The answer is here:

http://api.rubyonrails.com/classes/ActionController/Cookies.html


Alex


#5

Thanks for your reply.
I am setting the cookie to .home.com in my login function but when I
go to blog.home.com, the session isn’t being recognized.

Can anyone please guide me on where is the optimal place to set the
cookie?
Thanks
Frank

sach removed_email_address@domain.invalid wrote: softwareengineer 99 wrote:

Thanks'
Frank

Isn’t that just a matter of how you have your cookie set?

Instead of setting the domain of the cookie to ‘blog.home.com’ just set
it to ‘.home.com’ and then that cookie should be valid for any host
under the ‘home.com’ domain.


Posted via http://www.ruby-forum.com/.


#6

You need to set the session domain in your production.rb

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => ‘.suprglu.com’)

For develpment&&testing you should change test.rb, and development.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => ‘.localhost.com’)

then configure your /etc/hosts file to map localhost.com,
something.localhost.com to 127.0.0.1. You now have a subdomained
development setup at your disposal!

For functional tests you would place this into test/test_helper.rb

module ActionController
class TestRequest
def with_subdomain(subdomain=nil)
the_host_name = “localhost.com
the_host_name = “#{subdomain}.localhost.com” if subdomain
self.host = the_host_name
self.env[‘SERVER_NAME’] = the_host_name
self.env[‘HTTP_HOST’] = the_host_name
end
end
end

then for test suites needing subdomained requests you can add this to
your
setup:

@request.with_subdomain(‘primalgrasp’)

Zsombor


#7

Hi Zsombor,

Thank you very much for your reply.
I will test it out right now.

Thanks again.
Frank

Dee Z. removed_email_address@domain.invalid wrote: You need to set the session
domain in your production.rb

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => ‘.suprglu.com’)

For develpment&&testing you should change test.rb, and development.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(
:session_domain => ‘.localhost.com’)

then configure your /etc/hosts file to map localhost.com,
something.localhost.com to 127.0.0.1. You now have a subdomained
development setup at your disposal!

For functional tests you would place this into test/test_helper.rb

module ActionController
class TestRequest
def with_subdomain(subdomain=nil)
the_host_name = “localhost.com
the_host_name = “#{subdomain}.localhost.com” if subdomain
self.host = the_host_name
self.env[‘SERVER_NAME’] = the_host_name
self.env[‘HTTP_HOST’] = the_host_name
end
end
end

then for test suites needing subdomained requests you can add this to
your
setup:

@request.with_subdomain(‘primalgrasp’)

Zsombor

Company - http://primalgrasp.com
Thoughts - http://deezsombor.blogspot.com


#8

I spoke too soon as after clearing the cookies it works!
Zsombor, thank you so much for your time and assistance. I owe you one
:wink:

Frank

softwareengineer 99 removed_email_address@domain.invalid wrote: Hello
Zsombor,

You need to set the session domain in your production.rb

I placed the following code in production.rb, development.rb and
test.rb

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain
=> ‘.domain.com’)

and the functional tests snippet in test/test_helper.rb.

Then I restarted the server and logged in at domain.com. Then I went
to blog.domain.com and it’s not recognizing session and asking me again
for password.

Did I miss something?

I highly appreciate your assistance.

Frank
P.S. I just added your blog to my reading list :wink:


Brings words and photos together (easily) with
PhotoMail - it’s free and works with Yahoo!
Mail._______________________________________________
Rails mailing list
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


#9

On Feb 8, 2006, at 3:39 AM, softwareengineer 99 wrote:

Thanks’
Frank

Frank-

I think this is what you need. This line goes in config/environments/

production.rb or development.rb:

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update
( :session_domain => ‘.example.com’)

Note the . before example.com , that is what makes the sessions work

between subdomains.

Cheers-

-Ezra Z.
Yakima Herald-Republic
WebMaster
http://yakimaherald.com
509-577-7732
removed_email_address@domain.invalid


#10

Hello Zsombor,

You need to set the session domain in your production.rb

I placed the following code in production.rb, development.rb and
test.rb

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update(:session_domain
=> ‘.domain.com’)

and the functional tests snippet in test/test_helper.rb.

Then I restarted the server and logged in at domain.com. Then I went
to blog.domain.com and it’s not recognizing session and asking me again
for password.

Did I miss something?

I highly appreciate your assistance.

Frank
P.S. I just added your blog to my reading list :wink:


#11

ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update
( :session_domain => ‘.example.com’)

What if I don’t know session_domain at this stage. Can I set it up in
controller? How?