【发布时间】:2013-12-30 02:02:43
【问题描述】:
我正在为需要密码才能查看的特定页面构建一个非常基本的身份验证系统。我发现了其他几个听起来相似的问题,但唯一有明确解决方案的问题涉及似乎无法解决我的问题的配置设置。出于某种原因,$this->Session->write(...) 总是返回 false。
这是我的配置设置:
Configure::write('Session', array(
'defaults' => 'php'
));
这是我尝试在控制器操作中编写会话的地方:
private function _handle_auth_attempt( $object ) {
$submitted_pass = $this->request->data['Object']['password'];
$correct_pass = $object['Object']['password'];
$auth_cookie_name = $this->Object->auth_cookie_name($object);
debug($auth_cookie_name); //'Object1.pass'
debug($submitted_pass); //'foobar'
if ( md5($submitted_pass) == md5($correct_pass) ) {
$write1 = $this->Session->write( $auth_cookie_name, md5($submitted_pass) );
$write2 = CakeSession::write( $auth_cookie_name, md5($submitted_pass) );
debug($write1); //FALSE
debug($write2); //FALSE
return TRUE;
}
$this->Session->setFlash('The password you entered is incorrect.');
$this->redirect( $this->referer() );
}
更新
在_handle_auth_attempt()里面我加了:
$_SESSION['foo'] = 'bar';
$this->Session-read('foo'); //'bar'
...他们工作正常。所以我很确定这不是权限问题。
【问题讨论】:
-
你是在控制器中添加 SessionComponent 吗?
-
你清除浏览器缓存了吗?
-
@GuillemoMansilla 我调试了 $component,我在 ->write(...) 之前的数组中看到了 Session、Cookie 和 Auth。
-
@praveen 我换了浏览器,情况也一样。
标签: php session cakephp cakephp-2.0 session-cookies