Home > Article > Backend Development > COOKIE in PHP takes effect in time, and you can use php cookie to log in without refreshing. php clears cookies. How to set cookies in php?
Today I encountered the problem that PHP cookies must be refreshed before they take effect. You can solve it with the following method:
//PHP COOKIE setting function takes effect immediately and supports arrays
function cookie($var, $value = '' , $time = 0, $path = '', $domain = '', $s = false)
{
$_COOKIE[$var] = $value;
if (is_array($value) ) {
’’, $s);
}
} else {
} setcookie($var, $value, $time, $path, $domain, $s);
}
}
Like this You can get the cookie value directly without refreshing. Please see the PHP manual for cookie parameter details
Tips:In fact, these two sentences in this code are useful for timely updating of cookies:$_COOKIE[$var] = $value;
setcookie($var, $value, $time, $path, $domain, $s);
That is, the cookie is assigned twice at once
The above has introduced that COOKIE in PHP takes effect in a timely manner and can be used without refreshing, including cookie and php content. I hope it will be helpful to friends who are interested in PHP tutorials.