在php下设置了cookie,CI下set_cookie()方式,但是发现cookie不能马上生效,需要刷新后才能获取,后来在网上找到了一个解决办法,$_COOKIE[$var] = $value;多加一句就可以实现不刷新cookie生效
//PHP COOKIE设置函数立即生效,支持数组
function cookie($var, $value = '', $time = 0, $path = '', $domain = '', $s = false)
{
$_COOKIE[$var] = $value;
if (is_array($value)) {
foreach ($value as $k => $v) {
setcookie($var . '[' . $k . ']', $v, $time, $path, $domain, $s);
}
} else {
setcookie($var, $value, $time, $path, $domain, $s);
}
}