站点的 HTTP 和 HTTPS 部分之间的 Cookie 不同步
我正在使用 CakePHP (v 1.3) 和 Auth 组件。现在,所有 cookie 都不在 HTTP 和 HTTPS 之间的 snyc 中。
例如,用户可以通过HTTP登录而未通过HTTPS登录,或者更糟糕的是,用户A可以通过HTTP登录而用户B可以通过HTTPS登录。
其他事情也会发生这种情况(例如购物车中的商品),
我不知道发生了什么或如何解决它。
我需要做什么才能让它们在 HTTP 和 HTTPS 上拥有相同的 cookie?
I am using CakePHP (v 1.3), and the Auth component. Right now all the cookies are not in snyc between HTTP and HTTPS.
For example, a user can be logged in on HTTP and not logged in on HTTPS or even worse user A can be logged in on HTTP and user B can be logged in on HTTPS.
This is happening for other things as well (like items in cart)
I have no idea what is going on or how to fix it.
What do I need to do so that they have the same cookies on HTTP and HTTPS?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可能是由安全 cookie 引起的,该 cookie 仅在通过 https 访问页面时发送。如果通过 https 访问页面,CakePHP 会自动设置 session.cookie_secure。
要禁用此行为,请将
cake\libs 内的
ini_set('session.cookie_secure', 1);
更改为ini_set('session.cookie_secure', 0);
\cake_session.php我建议在应用程序端处理它,并允许仅通过 https 登录(和所有会员页面)。
This is probably caused by secure cookies, which are sent only when page is accessed over https. If page is accessed over https, CakePHP sets session.cookie_secure automatically.
To disable this behaviour, change
ini_set('session.cookie_secure', 1);
toini_set('session.cookie_secure', 0);
insidecake\libs\cake_session.php
I would recommend to deal with it at the application side and allow logging in (and all member pages) only over https.
修改核心代码大多数时候是一件坏事,在你的情况下,有可能做你需要的事情,但蛋糕的方式。
在 app/config/core.php 中:修改 Session.save 值
包含您想要的会话参数
在 app/config 中:创建一个 mysession.php 文件,其中 请注意,如果您将 cookie 设置为不安全,则使用 HTTPS 的大部分好处都会消失,因为由于 HTTPS 和 HTTP 使用相同的会话 cookie,因此很容易窃取它,然后也可以窃取 HTTPS 的会话。
我遇到过一个 Web 应用程序,其中包含通过 HTTPS 的管理部分和通过 HTTP 的公共部分,也需要会话。我设法通过指定两个不同的 cookie 名称来分隔这两个部分:
在 app_controller.php 中:
在 app/config 中,创建另一个名为 *mysession_https.php* 的文件
这会创建两个不同的会话,一个通过 HTTP,一个通过 HTTPS,但在我的情况很好,因为所有敏感或私有数据都通过 HTTPS 传输,而通过 HTTP 传输的部分只需要会话即可获得更流畅的导航。
Modifying the core code is most of the time a bad thing and in your case, there is a possibility to do what you need, but the Cake way.
In app/config/core.php: modify the Session.save value
In app/config: create a mysession.php file with the parameters you want for your session
Also be aware that if you set your cookies to be not secure, most of the benefit of using HTTPS is gone, because as the same session cookie is used for HTTPS and HTTP, it becomes easy to steal it and then to steal the session for HTTPS as well.
I had the case of a webapp with an admin part over HTTPS and a public part over HTTP that required session as well. I manage to separate both parts by specifying two different cookie names:
In app_controller.php:
And in app/config, create another file called *mysession_https.php* with
This creates two different sessions, one over HTTP and one over HTTPS, but in my case it was fine, since all sensitive or private data are over HTTPS and the part over HTTP requires a session only to get a smoother navigation.