CakePHP: Session-> write () not working

I am creating a very basic auth system for specific pages that require a password to view. I found several other questions that are similar, but the only ones that have clear solutions include configuration settings that don't seem to solve my problem. For some reason, $this->Session->write(...)always returns false.

Here is my configuration setting:

Configure::write('Session', array(
    'defaults' => 'php'
));

Here, where I am trying to write a session in a 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 great. Therefore, I am sure that this is not a permissions problem.

+1
source share
3

FALSE , . , ,

debug($auth_cookie_name);
+1

, "." cookie , Session->write() .

$this->Session->write('Object1.pass'); //FALSE
$this->Session->write('Object1pass'); //TRUE

, .

, , :

  • CakePHP "" , .
  • , , , , ...
  • FALSE, < - untested
  • , read() false.
0

/ :

$this->Session->write('User.still_login', 'Yes');

echo $this->Session->read('User.still_login'); // Yes as output
0

All Articles