【发布时间】:2015-06-01 22:08:59
【问题描述】:
我想在用户登录期间写入 cookie,并希望下次用户打开该页面时读取 cookie 名称并在登录前显示。以下是我使用的代码:-
var $components = array('Cookie');
function beforeFilter()
{
$this->Cookie->name = 'LOGIN_COOKIE';
$this->Cookie->time = time()+60*60*24*30; //cookie expire after 30 days
$this->Cookie->path = '/';
$this->Cookie->domain = 'example.com/';
$this->Cookie->secure = false;
$this->Cookie->key = '39lbkutg1i2l0kta6785d8qki5';
$this->Cookie->httpOnly = true;
}
在登录功能中
$this->Cookie->write('COOKIE_USER', array(
'name' => $UserDetails['SystemUser']['Name'],
'email' => $UserDetails['SystemUser']['email'],
'lastname' => $UserDetails['SystemUser']['LastName']
));
在我看来
$readCookie=$this->Cookie->read('COOKIE_USER');
但它给出了错误“缺少助手”
Error: CookieHelper could not be found.
Error: Create the class CookieHelper below in file: app/View/Helper/CookieHelper.php
请指导我。
【问题讨论】:
-
为什么你正在阅读 cookie 视图?您使用了 Cookie 组件,但尝试使用 cookie 助手读取而不加载它......
-
如果用户之前访问过我们的网站,我需要在视图中显示姓名和电子邮件。所以我必须在视图中阅读cookie。你知道如何在视图中显示姓名和电子邮件吗?
-
是的,我知道,请看下面的答案...
标签: php cakephp cookies cakephp-2.0