简体   繁体   English

在Rails和PHP之间共享会话数据

[英]Share session data between Rails and PHP

I have a Rails application that uses ActiveRecordStore for sessions. 我有一个使用ActiveRecordStore进行会话的Rails应用程序。 I need a PHP application running on a subdomain to share the session. 我需要在子域上运行的PHP应用程序来共享会话。

I have updated the environment to allow session cookies to be accessed across subdomains, but I don't know what the php application will have to do to access the session data. 我已经更新了环境,以允许跨子域访问会话cookie,但是我不知道php应用程序必须做什么才能访问会话数据。 Please could someone help me out with the next steps? 请有人帮我下一步吗?

Thanks in advance 提前致谢

I believe the best solution would be to turn handling of sessions over to Memcached for both PHP and Rails. 我相信最好的解决方案是将会话处理交给PHP和Rails的Memcached。 If you write a simple wrapper for each (a number available online actually), then you'll be able to access the same data from either application. 如果您为每个应用程序编写一个简单的包装器(实际上是一个在线可用的数字),那么您将能够从两个应用程序中访问相同的数据。

you need to configure in php.ini where the sessions data are stored. 您需要在php.ini中配置存储会话数据的位置。 but even after that i am not sure it will work as php / rails probably use different formats for storing sessions. 但即使在那之后,我不确定它是否会工作,因为php / rails可能会使用不同的格式来存储会话。

best would probably be to store variables as JSON in some file that both rails/php can access and then import into both languages (php/ruby-rails)? 最好是将变量作为JSON存储在两个rails / php都可以访问的文件中,然后导入两种语言(php / ruby​​-rails)吗?

Thanks for the answers guys. 谢谢你们的答案。 Eventually I decided against sharing the sessions themselves, instead opting to share a hashed cookie which both applications could use to verify a user was signed in. 最终,我决定不自己共享会话,而是选择共享一个哈希cookie,两个应用程序都可以使用该哈希cookie来验证用户是否已登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM