Codeigniter - cookies do not work in internet explorer 8

筅森魡賤 提交于 2019-12-10 19:55:15

问题


This code works in all browsers except Internet Explorer 8

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

        echo get_cookie('test_cookie');

How to solve this problem? Why does not set_cookie?


回答1:


try:

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



回答2:


I had a similar issue where only IE would refuse to accept a cookie. Turned out the computer's time zone wasn't set correctly (it was 17 hours ahead in the future, set to US PST while the server was in Australia), so what was happening is that the cookie was instantly expiring.




回答3:


I solved my problem using the function in helper

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);
}


来源:https://stackoverflow.com/questions/16075833/codeigniter-cookies-do-not-work-in-internet-explorer-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!