CakePHP cookie过期不工作 [英] CakePHP cookie expiration not working

查看:126
本文介绍了CakePHP cookie过期不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CakePHP中使用AppController我设置以下cookie设置:

Using AppController in CakePHP I set the following cookie settings:

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

我写两个cookie,但只有第一个获得正确的到期时间,

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

我使用 UsersController 这个模型:

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


推荐答案

尝试:

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

here 写入的第四个参数确定到期日期。我想当你设置属性,像你现在在beforeFilter()的方式,它只做一个cookie。需要仔细检查一下。

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.

这篇关于CakePHP cookie过期不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆