du0173 2013-07-26 11:14
浏览 26
已采纳

如何在两个不同的Web服务器(如xampp和tomcat)之间使用会话值。 [关闭]

I have a java web application running in tomcat and another php application running in lampp. I need to use single sign on between these two applications.

What is the best method to do it ? 1. To share the session between the two servers. If so how to do it. 2. To use cookies to share data between the web servers. In this case I need to encrypt and decrypt cookies. If so what is the best method to use encryption and decryption logic which is compatible with both php and java applications.

  • 写回答

1条回答 默认 最新

  • dqnek0079 2013-07-26 11:40
    关注

    Where a several methods of doing what you want:

    1. As sessions in PHP are stored in some temporary dir (configured by session.save_path option in php.ini), it's possible to use this files as sessions in your java application, but you'll have to make Java webApp know how to read this files, and save data back to it. The problem, that could happen is a blocking of this file. Every php process blocks session file while it is running, so no other program could read it while php is working. So, if you have high load - this problem would degrade performance of your web apps.

    2. In php you can write your own functions to save and load session data (http://www.php.net/manual/en/session.customhandler.php), where are a lot of php session handlers already written by others, and could be find in the Internet. This handler could use any storage to put and get sessions from. For example: mysql database, mongodb, even memcache (not recommended, because of non-persistence). You can use this way and store sessions in some data storage better then default file storage, and use it both from php and java. This is the best solution.

    3. And the last variant - save data into cookie. Of course, you can use some powerful crypting method which uses closed keys to encrypt and decrypt data, and store this data in cookie. But, the bad news is that your users would have a lot examples of your encrypted information, and, with some effort, powerfull computer and knowledge on decryption, evil hackers could get your sensitive data, that usually stored in session without afraid of loosing it. For example, you can place login, password and credit card number of logined user in it's session for fast access. You can say, that "first let them try to sneak a cookie from another user", but it's already a security hole, and next step is not so important.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 蓝桥oj3931,请问我错在哪里
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染