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_Cookieis not for setting cookies. It is a class used byZend_Http_Clientfor 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).