aneildo
aneildo

Reputation: 46

CakePHP cookie expiration not working

Using AppController in CakePHP I set the following cookie settings:

function beforeFilter() {
    $this->Cookie->name = 'Vinbeo';
    $this->Cookie->time = '7 Days';
}

I'm writing two cookies but only the first gets the right expiration time and the other expires when the browser is closed.

I'm using UsersController with this model:

$this->Cookie->write('name',$name);

Upvotes: 2

Views: 2282

Answers (1)

RabidFire
RabidFire

Reputation: 6330

Try this:

$this->Cookie->write('first_cookie', 'cookie1', false, '7 Days');
$this->Cookie->write('second_cookie', 'cookie2', false, '3 Days');

From here: The fourth parameter of write determines the expiry date. I think when you set properties like the way you are doing it now in the beforeFilter(), it does it only for the one cookie. Need to double check this though.

Upvotes: 1

Related Questions