Codeigniter - 在Internet Explorer 8中无法使用cookies

3

这段代码在除了Internet Explorer 8以外的所有浏览器中都能正常工作。

 $this->input->set_cookie(array(
                          'name'   => 'test_cookie',
                          'value'  => 'hello from cookie',
                          'expire' => 360000000,
                          'secure' => FALSE
                          ));

        echo get_cookie('test_cookie');

如何解决这个问题?为什么不能设置cookie?

1
Cookies没有被设置?如果不使用CodeIgniter,你能否设置它们? - Jeemusu
你能确认你的代码在Firefox、Chrome等浏览器上能正常工作吗? - itsme
这段代码在所有浏览器中都可以运行! - Almas Sarsenbayev
@AlmasSarsenbayev,您的IE浏览器启用了Cookie吗? - itsme
Cookies已在IE中启用,其他网站使用cookies正常。 - Almas Sarsenbayev
3个回答

2

我曾遇到类似的问题,只有IE浏览器无法接受cookie。后来发现电脑的时区设置不正确(比实际时间快了17个小时,被设置成美国太平洋标准时间,而服务器在澳大利亚),所以cookie立即过期了。


谢谢,我遇到了完全相同的问题 - 在使用微软提供的IE11开发虚拟机时。时钟上显示的时间是“正确”的,但它被设置为美国太平洋标准时间,因此实际上已经过去了。由于Cookie被忽略了,所以很难诊断!我尝试了很多方法,但是你的答案让我检查了虚拟机中的时钟。 - scipilot

0

我使用辅助函数解决了我的问题

function setcookie_ex($name, $value, $expire)
{
    $cookie_path = '/'; $cookie_domain = ''; $cookie_secure = false;

    // Enable sending of a P3P header
    header('P3P: CP="CUR ADM"');

    if (version_compare(PHP_VERSION, '5.2.0', '>='))
       setcookie($name, $value, $expire, $cookie_path, $cookie_domain, $cookie_secure, true);
    else
    setcookie($name, $value, $expire, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure);
}

0

尝试:

echo $this->input->cookie('test_cookie');

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接