CakePHP会话在同一个域上的两个应用程序之间共享 [英] CakePHP session sharing between two apps, on the same domain
问题描述
我有两个CakePHP应用程序在同一个域上工作。
它们位于 localhost:8080 / wishlist
和 localhost:8080 / lighthouse
。
每个单独的CakePHP应用程序都有Wishlist和lighthouse。
登录页面位于 localhost:8080 / lighthouse
,我希望灯塔应用程序生成的会话
目录结构为
/ htdocs
/ wishlist
/ app
/ config
....
/ lighthouse
/ app
/ config
....
我编辑了 core.php
每个应用程序的文件。我使用相同的会话cookie名称和相同的安全销售,但我不能在wishlist应用程序上获得会话。
如何在之间共享会话我的两个应用程序?
首先,安装 Firefox , Firebug 和 Firecookie 。
Cookie由多个部分组成:名称,值,域名,路径,过期日期等等,这将为Firebug添加一个Cookies标签。
默认情况下,CakePHP会将每个cookie的路径限制在应用程序的子目录中。例如,当您访问 / wishlist
时,将创建一个cookie,但它将限制在 / wishlist
子目录。当你然后去 / lighthouse
之前的cookie不会应用,所以认为你没有cookie /会话,创建一个新的限制为 / lighthouse
子目录。
您需要将创建的Cookie的路径更改为 /
,所以它们持久存在于所有子目录中。这应该像添加 ini_set('session.cookie_path','/');
到应用程序的 app / config / bootstrap.php
文件。
I am having two CakePHP application working on the same domain.
They are located at localhost:8080/wishlist
and localhost:8080/lighthouse
.
"Wishlist" and "lighthouse" are each separate CakePHP applications.
The login page is at localhost:8080/lighthouse
, and I want the session generated by the lighthouse application to be used in the wishlist application.
The directory structure is
/htdocs
/wishlist
/app
/config
....
/lighthouse
/app
/config
....
I have edited the core.php
file for each application. I am using the same session cookie name and the same security sale but I am not able to get the session on the wishlist application.
How can I share a session in between my two applications?
Firstly, install Firefox, Firebug and Firecookie. This will add a 'Cookies' tab to Firebug making it simple to inspect your cookies.
Cookies consist of multiple parts: name, value, domain, path, expires, etc. You are most interested in the 'path' part of the cookie here I believe.
By default CakePHP will restrict the path of each cookie to the subdirectory of your app. For example, when you visit /wishlist
, a cookie will be created but it will be restricted to the /wishlist
subdirectory. When you then go to /lighthouse
the previous cookie won't apply, so thinking that you have no cookie/session, a new one is created that is restricted to the /lighthouse
subdirectory.
You need to change the path of created cookies to /
so they persist across all subdirectories. This should be as easy as adding ini_set('session.cookie_path', '/');
to both application's app/config/bootstrap.php
files.
这篇关于CakePHP会话在同一个域上的两个应用程序之间共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!