【问题标题】:CakePHP Authcomponent session expires after using SSL unforce method使用 SSL unforce 方法后 CakePHP Authcomponent 会话过期
【发布时间】:2012-08-21 14:41:31
【问题描述】:

我在注册期间使用 SSL 5 页

https://www.example.com/step1
https://www.example.com/step2
https://www.example.com/step3 - 认证组件登录
https://www.example.com/step4
https://www.example.com/step5

在第 3 步之后,我正在使用 Auth 组件创建用户会话,该组件通过 Auth 组件自动登录用户。但是,在第 5 步之后,它会重定向到 http://www.example.com/welcome

我正在使用 SSL 组件非强制方法将 HTTPS 更改为 HTTP 。 一切正常,但问题是,一旦我从第 5 步(HTTPS)到达欢迎页面,我的身份验证组件会话就会过期。我试图调试它,但找不到任何解决方案。请注意,如果没有 HTTPS,所有步骤和会话都可以正常工作。

【问题讨论】:

标签: cakephp ssl cakephp-2.0


【解决方案1】:

AppController 类中的代码:

function beforeFilter() {
parent::beforeFilter();
$this->_setupSecurity();}

function _setupSecurity() {
$this->Security->blackHoleCallback = '_badRequest';
if(Configure::read('forceSSL')) {
    $this->Security->requireSecure('*');    }

}

/** * 主要的 SecurityComponent 回调。 * 处理丢失的 SSL 问题和一般的错误请求。 */

function _badRequest() {
if(Configure::read('forceSSL') && !$this->RequestHandler->isSSL()) {
    $this->_forceSSL();
} else {
    $this->cakeError('error400');
}
exit;}

/** * 重定向到同一页面,但使用 https 协议并退出。 */

function _forceSSL() {
$this->redirect('https://' . env('SERVER_NAME') . $this->here);
exit;

}

点击这个链接:也许你会得到你的解决方案..

https://stackoverflow.com/a/4473178/983624

【讨论】:

    【解决方案2】:

    如果您使用的是 Cakephp 2.0,请转到以下文件夹

    lib/Cake/模型/数据源/

    打开 CakeSession.php 文件并搜索以下行

    if (!isset($sessionConfig['ini']['session.cookie_secure']) && env('HTTPS'))
    {
            $sessionConfig['ini']['session.cookie_secure'] = 1; // Just comment this line and try it will works
    }
    

    【讨论】:

      猜你喜欢
      • 2011-10-17
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多