Question by Kunal
I am learning a Zend Framework. Its going really difficult to me as compare to CodeIgniter. I have a problem of the difference between normal cookies(php) and zend_http_cookies. I am using normal cookies in my Zend application, it works but I want to understand Zend_http_cookies and its pure concept, can anyone tell me this..
thnx in advance.
Answer by Kunal
PHP cookie :
A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.
In PHP you can set cookie like this :
setcookie("user", "username", time()+3600); //For getting cookie write: echo $_COOKIE["user"];
Zend_Http_Cookie is a class that represents an HTTP cookie. It provides methods for parsing HTTP response strings, collecting cookies, and easily accessing their properties.
You can instantiate it using :
$cookie = new Zend_Http_Cookie('user', 'user demo', '.example.com', time() + 3600, '/path');
A cookie object can be transferred back into a string, using the __toString() magic method. This method will produce a HTTP request “Cookie” header string, showing the cookie’s name and value, and terminated by a semicolon (‘;’). The value will be URL encoded, as expected in a Cookie header:
// Will print out 'user=user+demo;' : echo $cookie->__toString(); echo (string) $cookie; echo $cookie;
For advance you should read zend documentation from framework.zend.com
Answer by Starx
Zend_Http_Cookie is not related to normal cookies. It is a part of
Zend_Http_Client and is a class that represents an HTTP cookie.
It provides methods for parsing HTTP response strings, collecting cookies, and easily accessing their properties. It also allows checking if a cookie matches against a specific scenario, IE a request URL, expiration time, secure connection, etc.