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);
}
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
is not for setting cookies. It is a class used byZend_Http_Client
for sending and receiving data from sites that require cookies. To set cookies just use the standard PHP setcookie() function: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).Check Zend_Http_Cookie
You will get your cookie like following:
Use this way you can do it
in your controller do it code as
Try:
Ref: Zend Cookies
Your cookies are set by sending response. You can modify response in your code.
By default, the front controller sends response when it has finished dispatching the request; typically you will never need to call it. http://framework.zend.com/manual/1.12/en/zend.controller.response.html