How to get through a session between tomcat and php

Hey, I am in a WTF code situation running on a jsp tomcat server and trying to transfer session data (user ID, etc.) to php. I plan to rewrite php session processing using session_set_save_handler () my question is where does tomcat store session data (harddrive?) And what encoding does it use? or I'm wrong? I know that the idea of ​​mashing php and jsp is stupid, I just got this job and I'm angry too.

+1
source share
3 answers

Try to avoid sessions between different systems. You cannot share sessions between PHP and Java because

  • They work under different processes, maybe different machines. No shared memory.
  • Session data structures are completely different.
  • Serialization is incompatible.
  • Different flavors of cookie, "PHPSESSID" and "JSESSIONID".

You yourself must manage the session to share sessions. This is pretty tricky. Below are the components you should write,

  • Configure shared session storage, such as DB or memcached. The session is stored as a large blob.
  • Create shared session data structures. I just use value-name pairs. The same name must be used on both systems, and the values ​​must be string (UTF-8).
  • Use regular serialization. I would go with PHP session_encode (), which is pretty easy to handle in Java.
  • Process your own session cookie.
+6
source

You can try using database-based sessions to solve this problem. Assuming tomcat and apache have the same session hashes, maybe they can be migrated through servers? You need to look in the tomcat configuration file, and MUST be under something with a session prefix. This is where I will start. Typically, on a Ubuntu Linux server, it is under something like / etc / apache 2 / apache2.conf.

Hope this helps and good luck!

Kyle

+3
source

I believe that the default session manager for Tomcat will store session data in the SESSIONS.ser files in the "work" directory for your application.

You might want to create and configure your own session manager: http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html

+3
source

Source: https://habr.com/ru/post/1333701/


All Articles