CakePHP的多个应用程序具有相同的蛋糕图书馆和共享会话 [英] cakephp multiple apps with same cake library and shared session

查看:165
本文介绍了CakePHP的多个应用程序具有相同的蛋糕图书馆和共享会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是有运行的应用程序作为我们公司的公共网站CakePHP的,老板要我创建另一个应用程序为他们使用相同的用户账户及权限管理办公室的活动。

I was having cakephp running application as public website of our company, boss asked me to create another application for them to manage in-office activities using the same user-accounts and their privileges.

在该项目位于 D本地开发PC:/ WAMP / WWW /黑石结果
我刚才复制 D:/ WAMP / WWW /黑石/应用,并在同一位置粘贴它命名为办公室

On local development PC that project is located at D:/wamp/www/blackstone
I just copied D:/wamp/www/blackstone/app and pasted it at same location naming it office.

app文件夹路径是:

The app folder paths are:

D:/wamp/www/blackstone/app
D:/wamp/www/blackstone/office

我犯了'isAutorized','验证'和; 会话在'办公室'的AppController以prevent组件进行登录校验。使用以下URL被访问的应用程序:

I have committed 'isAutorized', 'Auth' & 'Session' component in 'office' appController to prevent checking for login. Apps are being accessed using the following URLs:

localhost/blackstone
localhost/blackstone/office

我要访问黑石的会话在办公室。我还没有找到一个解决方案。

I want to access 'Session' of blackstone in office. I have yet to find a solution.

目前我有 core.php中黑石为:

Configure::write('Session', array(
        'defaults' => 'cake',
        'cookie' => 'my_app',
        'timeout'  => 500,  // 8 hours + 20 min, 
        'cookie_path' => '/',
        )
    );

core.php中办公室应用程序为:

Configure::write('Session', array(
        'defaults' => 'cake',
        'cookie' => 'my_app',
        'timeout'  => 500,  // 8 hours + 20 min, 
        'cookie_path' => '../',
        )
    );

这导致了很多更多的变化。

and this led to a lot more changes.

我可以尝试改变?

推荐答案

在调试这样的事情,最好是尝试设置简单,愚蠢的参数至少容易出错,只是为了确保你能得到它第一次工作 - 然后再慢慢增加对要在使用的生产(如,更安全),看看precisely哪里,这可能打破什么复杂性。

When debugging something like this, it is best to try to set the simplest, stupidest parameters least prone to errors just to ensure you can get it working first -- and then slowly increase the complexity toward what you want to use in production (eg, more secure) to see precisely where this might break.

首先,确保在core.php中一定要设置Security.level =低 - 在这两个应用程序。否则,一个应用程序确实会引用检查(如果中等),甚至重新生成会话ID(如果高),这肯定会prevent共享。

First, make sure that in core.php make sure to set Security.level = "low" -- in both apps. Otherwise, an app does session referrer checks (if "medium") or even regenerates the session id (if "high") which would definitely prevent sharing.

复杂的两点我看到的是'默认'=>'蛋糕'和相应的cookie_path的价值观。 作为CakePHP的手册说,将其设置为蛋糕放在服务器目录中的相对于该应用程序会话cookie

The two points of complexity I see is 'defaults' => 'cake' and the corresponding 'cookie_path' values. As the CakePHP manual says, setting this to 'cake' places the server session cookie in a directory relative to that app.

您应该改为注释掉cookie_path线,然后设置'默认'=>'PHP'。这样,你知道,最起码在PHP将会把会话cookie在一个固定的目录在开发机器上。

You should instead comment out the cookie_path lines, then set 'defaults' => 'php'. This way you know that at the very least that PHP will place the session cookies in one fixed directory on your development machine.

如果您必须切换回'蛋糕',然后确保你的'cookie_path参数其实都是写在一个单一的共享目录服务器cookie文件。其实看一下被写进了预期目录时您访问在浏览器中这两个应用的文件。如果两个应用程序编写的会话cookie到不同的目录,则必须解决您cookie_path PARAMS相匹配的应用程序显然不共享。此外,根据您的CakePHP的版本,你可能需要写这个参数作为,而不是下面的你怎么有它,以便使其生效:'INI​​'=>阵列('session.cookie_path'=>'/应用/ DIR')

If you must switch back to 'cake', then ensure that your 'cookie_path' parameters are in fact writing the server cookie file in a single shared directory. Actually look at the files being written into the expected directories when you are visiting both apps in the browser. If the two apps are writing session cookies into different directories, then you must fix your cookie_path params to match as the apps obviously aren't sharing. Also, depending on your CakePHP version, you might need to write this parameter as the following instead of how you have it in order for it to take effect: 'ini' => array('session.cookie_path' => '/app/dir')

最后,仔细检查该网站域名,Cookie路径,和所有其他的会话cookie的参数是完全一致的。 (您可以为您在您的Chrome网络检查客户端蛋糕会话Cookie)。如果有什么不匹配,那么应用程序将无法分享。

Finally, double-check that the site domain, "cookie path", and every other session cookie parameter are absolutely identical. (You can check for the client-side Cake session cookies in your Chrome web inspector.) If anything mismatches, then the apps will fail to share.

这篇关于CakePHP的多个应用程序具有相同的蛋糕图书馆和共享会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆