问题
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