user2636924
user2636924

Reputation:

setcookie() do not set value in chrome

hi all i am facing problem with setcookie() in chrome only. It is working fine in firefox. this is my function where i am using cookie

 function step3($voice_choice = null)
 {
    if (!empty($voice_choice)) 
    {
        setcookie("voice_choice", $voice_choice, time() + 2000, "/");
    }
 }

when I print $_COOKIE output is

   Array ( [CAKEPHP] => s247c7mlagt5am6h323cm7pqj0 [voice_choice] => favicon.ico )

the value of voice_choice is not what i set in above function.

Upvotes: 2

Views: 284

Answers (1)

Brett Stewart
Brett Stewart

Reputation: 478

If your using CakePHP why not do it their way?

public $components = array('Cookie');

$cookieTime = '8 weeks';  //The amount of time you want the cookie to last

if ( !empty($voice_choice) )
  this->Cookie->write('voice_choice', $voice_choice, true, $cookieTime);

Also for debugging cookies a nice trick in Chrome is:

Inspect Element -> Resources Tab -> Cookies -> yoursite (local.yoursite.com) to see if the cookie is being written.

Upvotes: 1

Related Questions