0

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?

4

3 に答える 3

0

私は同じ問題 (CakePHP 1.3.7) を抱えていましたが、今では write() メソッド内に期間を入れた場合にのみ機能します:

$this->Cookie->write ("cookie_name", "Some value", true, "+1 months");
于 2011-05-09T15:30:13.260 に答える
0

セッションとして Cookie を使用している場合、時間は 0 に設定されます。つまり、ブラウザを閉じると有効期限が切れるように設定されます。以下のコードに示すように、コントローラーでこの数値を変更してみてください。それが違いを生むかどうかを確認してください。私はこれをテストしていませんが、試してみる価値はあります。

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!';
}
于 2010-10-19T14:30:17.827 に答える
0

これで問題が解決することは保証できませんが、セッションを適切に構成する方法を説明できます。

まず、Security.timeout変数を設定します。これは秒単位のタイムアウト値を表しますが、これはセッションの有効期限とは異なります。この数値は、変数の設定に応じて定数値で乗算されSecurity.levelます。

「高」= x 10、「中」= x 100、「低」= x 300、

これが有効期限を与えるものです。たとえば、Session.timeoutが 30 でSecurity.levelが低い場合、セッションは 30*300 秒、つまり 150 分で期限切れになります。

于 2010-10-19T03:28:44.187 に答える