Cakephp Authcomponent会话在使用SSL unforce方法后到期

时间:2012-08-21 14:41:31

标签: cakephp ssl cakephp-2.0

  1. 在注册期间使用SSL 5页

      

    https://www.mysite.com/step1

         

    https://www.mysite.com/step2

         

    https://www.mysite.com/step3 - 验证组件登录

         

    https://www.mysite.com/step4

         

    https://www.mysite.com/step5

  2. 在第3步之后,我正在使用Auth Component创建用户的Session(自动让用户通过Auth组件登录)。但是在第5步之后它将重定向到下一页

      

    http://www.mysite.com/welcome

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

2 个答案:

答案 0 :(得分:3)

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

LIB /蛋糕/型号/数据源/

打开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
}

答案 1 :(得分:2)

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