【问题标题】:CakePHP Authcomponent session expires after using SSL unforce method使用 SSL unforce 方法后 CakePHP Authcomponent 会话过期
【发布时间】:2012-08-21 14:41:31
【问题描述】:
【问题讨论】:
标签:
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
}