【问题标题】:CodeIgniter cookie setter issueCodeIgniter cookie 设置器问题
【发布时间】:2015-05-14 17:37:32
【问题描述】:

以下没有在codeigniter中设置cookie。

$this->load->helper('cookie');
if (!$this->input->cookie('xx'))
{
    //Cookie not set, first visit
    $cookie = array(
        'name'   => 'xx',
        'value'  => '1',
        'expire' => (10 * 365 * 24 * 60 * 60),
        'path'   => '/',
        'prefix' => '',
        'secure' => TRUE
    );
    $this->input->set_cookie($cookie);
}

检查了浏览器,甚至使用了 vardump($this->input->cookie('xx'));得到结果为假。

【问题讨论】:

标签: php codeigniter cookies


【解决方案1】:

尝试从阵列中移除安全装置

$this->load->helper('cookie');
if (!$this->input->cookie('xx'))
{
    //Cookie not set, first visit
    $cookie = array(
        'name'   => 'xx',
        'value'  => '1',
        'expire' => (10 * 365 * 24 * 60 * 60),
        'path'   => '/',
        'prefix' => ''
    );
    $this->input->set_cookie($cookie);
} // This may work

【讨论】:

    【解决方案2】:

    使用了 Http 连接,因此如果变量 'secure' 设置为 true,则不会设置 cookie。 Codeigniter uses setcookie() to set the value

    所以删除安全值成功设置cookie并可以获取值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多