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?

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?

WBOY
WBOYOriginal
2016-07-29 08:54:58860browse

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

Original address: http:// www.cnblogs.com/loveyouyou616/archive/2012/11/22/2782512.html


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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn