CakePHP:Session-> write()不工作 [英] CakePHP: Session->write() not working

查看:199
本文介绍了CakePHP:Session-> write()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为需要密码才能查看的特定网页构建一个非常基本的身份验证系统。我发现几个其他问题听起来相似,但唯一有明确的解决方案涉及配置设置,似乎无法解决我的问题。由于某种原因 $ this-> Session-> write(...)总是返回false。



这是我的配置设置:

 配置:: write('Session',array(
'defaults'=& 'php'
));

这是我尝试在控制器操作中写入会话的位置:

 私人函数_handle_auth_attempt($ object){
$ submitted_pa​​ss = $ this-> request-> data ['Object'] ['password' ];
$ correct_pass = $ object ['Object'] ['password'];
$ auth_cookie_name = $ this->对象 - > auth_cookie_name($ object);

debug($ auth_cookie_name); //'Object1.pass'
debug($ submitted_pa​​ss); //'foobar'

if(md5($ submitted_pa​​ss)== md5($ correct_pass)){
$ write1 = $ this-> Session-> write($ auth_cookie_name, md5($ submitted_pa​​ss));
$ write2 = CakeSession :: write($ auth_cookie_name,md5($ submitted_pa​​ss));
debug($ write1); // FALSE
debug($ write2); // FALSE
return TRUE;
}

$ this-> Session-> setFlash('您输入的密码不正确。
$ this-> redirect($ this-> referer());

}

更新

内部 _handle_auth_attempt()我添加:

 code> $ _ SESSION ['foo'] ='bar'; 
$ this-> Session-read('foo'); //'bar'

...他们工作得很好。所以我很确定这不是权限问题。

解决方案

从源代码,FALSE的一个可能性是会话名称为空。
那么你可以检查一下结果是什么。

  debug($ auth_cookie_name); 


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.

Here's my config setting:

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() );

}

Update

Inside _handle_auth_attempt() I added:

$_SESSION['foo'] = 'bar';
$this->Session-read('foo'); //'bar'

...and they work fine. So I'm pretty sure this isn't a permissions problem.

解决方案

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-> write()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆