大家好,我只在 chrome 中遇到setcookie()
的问题。它在火狐中工作正常。这是我使用 cookie 的功能
function step3($voice_choice = null)
{
if (!empty($voice_choice))
{
setcookie("voice_choice", $voice_choice, time() + 2000, "/");
}
}
当我打印 $_COOKIE 时,输出是
Array ( [CAKEPHP] => s247c7mlagt5am6h323cm7pqj0 [voice_choice] => favicon.ico )
voice_choice
的值不是我在上面的函数中设置的值。
如果你使用CakePHP,为什么不按照他们的方式去做呢?
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);
同样为了调试cookie,Chrome中的一个很好的技巧是:
检查元素 -> 资源选项卡 -> Cookie -> yoursite (local.yoursite.com) 以查看是否正在写入 cookie。