CakePHP:Session-& gt; write()无法正常工作 [英] CakePHP: Session->write() not working
问题描述
我正在为需要密码才能查看的特定页面构建一个非常基本的身份验证系统.我发现了其他一些听起来很相似的问题,但是唯一有明确解决方案的问题涉及似乎无法解决我问题的配置设置.由于某些原因, $ this-> Session-> write(...)
始终返回false.
I'm building a very basic auth system for specific pages which require a password to view. I've found several other questions that sound similar, but the only ones with clear solutions involve config settings that don't seem to resolve my problem. For some reason $this->Session->write(...)
always returns false.
这是我的配置设置:
Configure::write('Session', array(
'defaults' => 'php'
));
在这里,我尝试在控制器操作中编写会话:
Here's where I try to write the session in the controller action:
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'
...他们工作正常.因此,我很确定这不是权限问题.
...and they work fine. So I'm pretty sure this isn't a permissions problem.
推荐答案
从源代码中,FALSE的一种可能是会话名称为空.那么您可以检查一下结果是什么
From the source code, one possibilities of FALSE is that the session name is empty. So can you check what result is
debug($auth_cookie_name);
这篇关于CakePHP:Session-& gt; write()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!