apache 如何在tomcat和php之间传递会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1460002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to pass a session between tomcat and php
提问by Leon Fedotov
Hey, I am in a WTF code situation working on a jsp tomcat server and trying to pass session data (user id, etc.) to php. i am planning to rewrite php session handling with session_set_save_handler()my question is where does tomcat stores it session data (harddrive?) and what kind of encoding does it uses? or am i on the wrong path? i know the idea of mashing php and jsp is stupid just got this assignment and i am pissed too.
嘿,我在一个 WTF 代码情况下在 jsp tomcat 服务器上工作并试图将会话数据(用户 ID 等)传递给 php。我打算用session_set_save_handler()重写 php 会话处理 我的问题是 tomcat 在哪里存储它的会话数据(硬盘?)它使用什么样的编码?还是我走错了路?我知道将 php 和 jsp 混合的想法是愚蠢的,刚拿到这个任务,我也很生气。
回答by ZZ Coder
Try to avoid sessions between different systems. You can't really share sessions between PHP and Java because,
尽量避免不同系统之间的会话。你不能真正在 PHP 和 Java 之间共享会话,因为,
- They run under different processes, maybe different machines. There is no shared memory.
- Their session data structures are totally different.
- The serialization is not compatible.
- Different cookie flavors, "PHPSESSID" vs. "JSESSIONID".
- 它们在不同的进程下运行,可能在不同的机器下运行。没有共享内存。
- 它们的会话数据结构完全不同。
- 序列化不兼容。
- 不同的 cookie 口味,“PHPSESSID”与“JSESSIONID”。
You pretty much have to do session management yourself to share sessions. It's pretty complicated. Following are the components you have to write,
您几乎必须自己进行会话管理才能共享会话。这很复杂。以下是您必须编写的组件,
- Setup a common session store, like a DB or memcached. The session is stored as big blob.
- Design a common session data structures. I just use name-values pairs. The same name must be used on both systems and the values must be string (UTF-8).
- Use a common serialization. I would go with PHP's session_encode(), which is fairly easy to handle on Java.
- Handle your own session cookie.
- 设置一个通用的会话存储,如 DB 或 memcached。会话存储为大 blob。
- 设计一个通用的会话数据结构。我只使用名称-值对。在两个系统上必须使用相同的名称,并且值必须是字符串 (UTF-8)。
- 使用通用序列化。我会使用 PHP 的 session_encode(),它在 Java 上很容易处理。
- 处理您自己的会话 cookie。
回答by Kyle J. Dye
You could try using database driven sessions to solve this issue. Assuming that tomcat and apache have the same session hashes, it may be possible to transfer them across servers? You need to look in the tomcat config file and it SHOULD be under something prefixed with session. That is where I would start. Typically, on an Ubuntu linux server it would be under something like /etc/apache2/apache2.conf.
您可以尝试使用数据库驱动的会话来解决此问题。假设 tomcat 和 apache 具有相同的会话哈希,是否可以跨服务器传输它们?您需要查看 tomcat 配置文件,它应该位于以 session 为前缀的内容下。那就是我要开始的地方。通常,在 Ubuntu linux 服务器上,它位于 /etc/apache2/apache2.conf 之类的目录下。
I hope this helps and good luck!
我希望这个帮助能祝你好运!
Kyle
凯尔
回答by Matt Sidesinger
I believe the default session manager for Tomcat will store session data in a SESSIONS.ser files in the "work" directory for your application.
我相信 Tomcat 的默认会话管理器会将会话数据存储在应用程序“工作”目录中的 SESSIONS.ser 文件中。
You may want to create and configure your own session manager: http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html
您可能想要创建和配置您自己的会话管理器:http: //tomcat.apache.org/tomcat-5.5-doc/config/manager.html

