I have surfed a lot. I would like to assign and retrieve a value using a COOKIE. How can i do in ZF2? I saw a lot of examples for assigning value in cookie. Please explain that how to retrieve a value from cookie.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A cookie in HTTP (see RFC 2109 simply something stored in the request and send every time a request is made. A response can add other parameters to be stored additionally to the already existing cookies.
So the cookie retrieval is done via the
Request, to update a cookie you use theResponse. According to RFC 2109 you use respectively theCookieheader and theSet-Cookieheader. You can thus directly access these headers viaOr set cookies via:
Things are made a little bit easier though because there is a proxy at the request and response to directly access the cookie:
Keep in mind the
CookieandSet-Cookieheaders implement theArrayObjectobject. To check whether a cookie is present in the request, you can thus useoffsetExists:/update:
If you want to modify properties of the cookie, you are also here modifying the
Set-Cookieheader. Take a look at the class on Github for all the methods available.A slight summary: