문제

So, I've tried many many things, but still always end up with Cookies that have the duration set to "Session" when looked at with Developers Tools in Google Chrome. Here are my current settings:

core.php:

Configure::write('Session.cookie', 'session');
Configure::write('Session.timeout', '3600');
Configure::write('Session.start', true);
Configure::write('Security.level', 'high');

users_controller.php

$this->Cookie->write('xHi1PeWmAw', $user_record['User']['id']);

I tried changing the Security.level, the Session.timeout, using $this->Cookie->time = 3600; and combining all that, but I can't seem to be changing that duration. Also I tried with short and long durations, given that I would ideally for this cookie to last as long as possible. Can you please tell me what I am doing wrong?

도움이 되었습니까?

해결책

I had the same problem (CakePHP 1.3.7) and now it works only if I put the duration within the write() method:

$this->Cookie->write ("cookie_name", "Some value", true, "+1 months");

다른 팁

Though I cannot guarantee this will fix your issue I can explain how to properly configure the sessions.

First you set your Security.timeout variable. This represents a timeout value in seconds, but this does not equal your sessions expiration time. This number is multiplied by a constant value depending on the setting of your Security.level variable.

'high' = x 10, 'medium' = x 100, 'low' = x 300,

This is what gives you your expiration time. For example, if you have a Session.timeout of 30, and a Security.level of low, your sessions will expire in 30*300 seconds, or 150 minutes.

If you you're using cookies as a session then it's time is set to 0. Which means it is set to expire when the browser closes. You could try to change this number in the controller as shown in the code below. See if that makes a difference. I have not tested this, but it is worth a shot.

var $components = array('Cookie');
function beforeFilter() {
   $this->Cookie->name = 'baker_id';
   $this->Cookie->time = 3600; // or '1 hour' //IF 0 THIS IS A SESSION COOKIE
   $this->Cookie->domain = 'example.com';
   $this->Cookie->secure = true; //i.e. only sent if using secure HTTPS
   $this->Cookie->key = 'qSI232qs*&sXOw!';
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top