在 Ruby 和 PHP 之间共享会话 [英] Sharing a session between Ruby and PHP
问题描述
是否可以在子域上的 PHP 应用程序和其他子域上的 Ruby 应用程序之间共享会话?
Is it possible to share a session between my PHP app on a subdomain and my Ruby apps on my other subdomains?
我真的不知道从哪里拿它.我知道我可以手动将域设置为根域,以便 cookie 对所有子域都有效,但是我如何从/向会话获取/设置内容,以便在子域之间共享?
I don't really know where to take it from here. I know I can manually set the domain to the root one so that the cookie is valid for all the subdomains, but how would I get/set stuff from/to the session so that it's shared across the subdomains?
我主要想用它来共享我整个子域的登录信息.
I mainly want to use this to share login for my whole subdomains.
为了知识起见,如果这是解决问题的错误方法,尽管可行,我想了解如何去做,为什么不应该这样做.
For the sake of knowledge, if it is the wrong approach to the problem, albeit a doable one, I'd like to understand both how to do it, and why should I not.
谢谢大家!
推荐答案
如果您想以这种方式共享会话(跨 PHP/Java/Ruby/etc),您需要从数据库中保存会话(并访问它们).
If you want to share sessions in that manner (accross PHP/Java/Ruby/etc), you need to save sessions (and access them) from a Database.
参见:http://php.net/manual/en/function.session-set-save-handler.php
而且您需要在 Ruby 中采用相同的方法.
And you would need an identical approach in Ruby.
要跨域共享 cookie,您还需要更改 session.cookie_domain
的 PHP 会话配置选项,从默认的 ""
(插入您的域名)至:".yourhost.com"
(注意前缀句点).
To share cookies across domains, you also need to change the PHP session configuration option for session.cookie_domain
from the default of ""
(which inserts your domain name) to: ".yourhost.com"
(note the prefixed period).
这篇关于在 Ruby 和 PHP 之间共享会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!