Christian Strang
Christian Strang

Reputation: 8530

CakePHP 2.1 $this->Session->write is not working

I included the 'Session' Component and the helper in my AppController.php Now, if I use $this->Session->write('App.testString', 'test); the Session is not created, or at least I don't receive the string when I do echo $this->Session->read('App.testString');.

Do I have to change any settings for Sessions to work?


Inside a controller function I can write and read a session, but if I want to read the session inside a different function (of the same controller) I don't get a value back.

Upvotes: 2

Views: 9493

Answers (1)

Christian Strang
Christian Strang

Reputation: 8530

I found the solution: By default CakePHP uses the folder which is set in php.ini. This folder couldn't be accessed in my hosting-environment (and I was not allowed to change the php.ini).

In this situation, you have to change in the core.php where session files are stored. This is what I had before:

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

I changed it to this one:

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

This way, cake uses his own tmp-folder to store the session files. Also make sure that the tmp folder and his subfolders are writeable.

Upvotes: 7

Related Questions