[英]Share PHP session between multiple web applications
I have two web applications on the same domain (a CMS and an E-Commerce platform) and I would like to share session data between them. 我在同一个域(CMS和电子商务平台)上有两个Web应用程序,我想在它们之间共享会话数据。 I can easily set it up so they both use the same session, but there is too much potential for variable name collisions in the $_SESSION variable.
我可以很容易地设置它们,因此它们都使用相同的会话,但$ _SESSION变量中存在太多可能的名称冲突。 I thought I could use named sessions, but I couldn't get it to work either:
我以为我可以使用命名会话,但我无法让它工作:
session_name("WEB_APP_ONE");
session_start();
$webAppOneData = $_SESSION;
session_write_close();
//var_dump($_SESSION) = all of the session data for web app one is still contained in $_SESSION even though I closed the session with session_write_close()
session_name("WEB_APP_TWO");
session_start();
$_SESSION['WEB_APP_ONE'] = $webAppOneData;
//var_dump($_SESSION) = all of the session data for web app one is still here
I'm not sure if this is possible, but I'd like to know if it is! 我不确定这是否可行,但我想知道它是否可行!
Note: the actual use-case I'm getting at is being able to show how many products are in the visitor's cart in the CMS. 注意:我正在使用的实际用例是能够显示CMS中访问者购物车中有多少产品。 The cart data is stored in the e-commerce platform's session, but I need to show from the header of the CMS.
购物车数据存储在电子商务平台的会话中,但我需要从CMS的标题中显示。 I want there to be seamless integration between the CMS and shopping cart.
我希望在CMS和购物车之间实现无缝集成。
I would recommend just name-spacing the sessions with a nested array: 我建议只使用嵌套数组对会话进行名称间隔:
$_SESSION['app1']['app1var'] = 'value';
$_SESSION['app2']['app2var'] = 'value';
You might also consider storing and retrieving session info from a database instead, using the session only to store user auth information which tells you which database row(s) to access. 您也可以考虑从数据库中存储和检索会话信息,仅使用会话来存储用户身份验证信息,该信息告诉您要访问哪些数据库行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.