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 9273951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:14:11+00:00 2026-06-18T16:14:11+00:00

I am trying to store variables in cookies, using the Symfony 1.4 framework. Here

  • 0

I am trying to store variables in cookies, using the Symfony 1.4 framework. Here is a snippet of my sfAction derived class:

class productActions extends sfActions
{
    public function preExecute()
    {
        $this->no_registration_form = true;
        $request = $this->getRequest();

        $cookie_value = $request->getCookie('pcatid');
        $this->prod_category_id = (!isset($cookie_value)) ? 0 : $cookie_value;

        $cookie_value = $request->getCookie('pitid');
        $this->product_item_id = (!isset($cookie_value)) ? 0 : $cookie_value;

        $cookie_value = $request->getCookie('pcatnm');
        $this->product_category_name = (!isset($cookie_value)) ? null : base64_decode ($cookie_value);

        $cookie_value = $request->getCookie('pipnm');
        $this->product_info_partial_name = (!isset($cookie_value)) ? null : $cookie_value;

        $cookie_value = $request->getCookie('protl');
        $this->title = (!isset($cookie_value)) ? null : base64_decode ($cookie_value);
    }

    public function postExecute()
    {
        $expire = time()+2592000;
        $path = '/products/';
        $response = $this->getResponse();

        $value = $this->prod_category_id;
        if (isset($value))
            $response->setCookie('pcatid', $value, $expire, $path);

        $value = $this->product_item_id;
        if (isset($value))
            $response->setCookie('pitid', $value, $expire, $path);

        $value = base64_encode($this->product_category_name);
        if (isset($value))
            $response->setCookie('pcatnm', $value, $expire, $path);

        $value = $this->product_info_partial_name;
        if (isset($value))
            $response->setCookie('pipnm', $value, $expire, $path);

        $value = base64_encode($this->title);
        if (isset($value))
            $response->setCookie('protl', $value, $expire, $path);        
    }

    public function executeIndex(sfWebRequest $request)
    {
        // uses defaults or settings stored in cookies
    }

    ... // other functions that set the required instance member fields
}

I have stepped through the code in a debug session, and I can see that the cookie values are being collated in the sfWebResponse variable – however, no cookies are being set – and this is demonstrated in the preExecute() function – all the cookies retrieved have value null.

Why is this happening?

  • 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-18T16:14:12+00:00Added an answer on June 18, 2026 at 4:14 pm

    I’ve made a simple test on a fresh symfony project.

    I’ve copy/pasted your preExecute & postExecute and I’ve added a simple action with an empty template:

    public function executeIndex(sfWebRequest $request)
    {
      var_dump($_COOKIE);
    
      $this->prod_category_id          = 123;
      $this->product_item_id           = 456;
      $this->product_category_name     = 789;
      $this->product_info_partial_name = 159;
      $this->title                     = 753;
    }
    

    And I’ve changed this line $path = '/products/'; to $path = '/';.

    On the first try, I don’t have any cookies so I’ve nothing:

    array
      empty
    

    And on refresh, cookies were defined and I can see them:

    array
      'symfony' => string 'c04khrspp5fmg3sh797uq9c9s1' (length=26)
      'pcatid' => string '123' (length=3)
      'pitid' => string '456' (length=3)
      'pcatnm' => string 'Nzg5' (length=4)
      'pipnm' => string '159' (length=3)
      'protl' => string 'NzUz' (length=4)
    

    What can be wrong from your code, is that you set the cookie path to /products/. Which means, you’ll be able to access these cookie only when your are on http://exemple.com/products/....

    If you try to access these cookies on http://exemple.com/, you’ll get nothing.

    If this doesn’t solve your problem, could you paste an example of an actions from where you got the problem with the defined uri (at least the part after the domain).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use a singleton to store variables that will be used
I am trying to create a php array where I can store 2 variables
I'm trying to store an image into an SQL database without using temporary files.
I'm trying to store variables in localStorage on my mobile website so if the
I'm trying to use flask.g to store variables that can be accessed in other
I am trying to store a value in a model class, for example, values
I have a problem with cookies. Basically I'm trying to store the user's session
I have been trying to store global variables in form of NSDATE but it
I'm trying to store URL's in my environment variables. So for instance ENV['SET_COOKIE_URL'] =
I am trying to store any and all variables sent to the site in

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.