Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9109953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:09:47+00:00 2026-06-17T03:09:47+00:00

I have surfed a lot. I would like to assign and retrieve a value

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:09:48+00:00Added an answer on June 17, 2026 at 3:09 am

    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 the Response. According to RFC 2109 you use respectively the Cookie header and the Set-Cookie header. You can thus directly access these headers via

    $this->getRequest()->getHeaders()->get('Cookie')->foo = 'bar';
    

    Or set cookies via:

    $this->getResponse()->getHeaders()->get('Set-Cookie')->foo = 'bar';
    

    Things are made a little bit easier though because there is a proxy at the request and response to directly access the cookie:

    public function fooAction()
    {
      $param = $this->getRequest()->getCookie()->bar;
    
      $this->getResponse()->getCookie()->baz = 'bat';
    }
    

    Keep in mind the Cookie and Set-Cookie headers implement the ArrayObject object. To check whether a cookie is present in the request, you can thus use offsetExists:

    if ($cookie->offsetExists('foo')) {
        $param = $cookie->offsetGet('foo');
    }
    

    /update:

    If you want to modify properties of the cookie, you are also here modifying the Set-Cookie header. Take a look at the class on Github for all the methods available.

    A slight summary:

    $cookie = $this->getResponse()->getCookie();
    $cookie->foo = 'bar';
    $cookie->baz = 'bat';
    
    $this->setDomain('www.example.com');
    $this->setExpires(time()+60*60*24*30);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a history list in my app. I have surfed
i have this issue working but i would like to know if there is
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have got a method which returns IEnumerable<User> which I have been using Linq /
I'm working on a solution where I have a WPF project that is using
I am interested in building web applications using Ruby on Rails. I surfed the
Have a photography site that I want to prevent image copying from. How can
I want to learn doing RESTful webservices. I have surfed the web some hours
I have created a 3d map using rgl.surface(), mainly following Shane's answer in this
I'm running a simple LIKE search on a table but i can't seem to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.