在zend框架中设置cookie [英] set cookie in zend framework

查看:78
本文介绍了在zend框架中设置cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是zend框架的新手。我已经编写了这段代码来在我的网站中设置cookie。

I am new to zend framework. I have write this code to set cookie in my website.

public function setCookie($data){
    $email_cookie = new Zend_Http_Cookie('user_email_id', $data['user_email_id'], $_SERVER['HTTP_HOST'], '', FALSE);
    $pass_cookie = new Zend_Http_Cookie('user_password', $data['user_password'], $_SERVER['HTTP_HOST'], '', FALSE);
    $cookie_jar = new Zend_Http_CookieJar();
    $cookie_jar->addCookie($email_cookie);
    $cookie_jar->addCookie($pass_cookie);
}

我什至不知道通过编写此代码是否设置了cookie?现在
如果我想检索cookie,该怎么办?

I dont even know by writing this code, my cookie is set or not? now If I want to retrieve the cookie then how can I do it?

推荐答案

Zend_Http_Cookie 不用于设置cookie。 Zend_Http_Client 使用此类从需要cookie的站点发送和接收数据。要设置cookie,只需使用标准的PHP setcookie()函数:

Zend_Http_Cookie is not for setting cookies. It is a class used by Zend_Http_Client for sending and receiving data from sites that require cookies. To set cookies just use the standard PHP setcookie() function:

setcookie('user_email_id', $data['user_email_id'], time() + 3600, '/');
setcookie('user_password', $data['user_password'], time() + 3600, '/');

这将设置cookie在1小时内过期。然后,您可以使用 $ _ COOKIE ['user_email_id'] $ _ COOKIE ['user_password'] 来访问这些请求;或者,如果您使用的是ZF的MVC类: $ this-> getRequest()-> getCookie('user_email_id')(通过控制器方法)。

this will set cookies that expire in 1 hour. You can then access these on subsequent requests using $_COOKIE['user_email_id'] and $_COOKIE['user_password']; or if you are using ZF's MVC classes: $this->getRequest()->getCookie('user_email_id') (from a controller method).

这篇关于在zend框架中设置cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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