For example:
Copy code The code is as follows:
$USERID="PHPer";
$CookieTime=0;
setcookie("USERID", "$USERID", time()+ $CookieTime,"/","btcuxiao.com");
?>
You will find that after this statement is executed, there is nothing in the Cookie, and the next page will show that there is no COOKIE variable value of $USERID.
The analysis of the problem is as follows:
First of all, the value of "Cookie expiration time" set in the browser process is not the current Unix timestamp + 0. If it is set to the browser process, just set the expiration time to 0 directly.
Secondly, I don’t know what domain name you used when testing this page. If you set "btcuxiao.com", it means that you must use "btcuxiao.com" to access the cookie for it to be effective. In fact, if you have many domain names If you access this page, then this place can be empty or the domain name accessing this cookie is under the same domain, then set it to ".btcuxiao.com", remember there is a "dot" in front of it
If you write the above program like this , may work:
Copy code The code is as follows:
$USERID="PHPer";
$CookieTime=0;
setcookie("USERID", "$USERID", 0 ,"/","");
echo (isset($_COOKIE['USERID']) ? $_COOKIE['USERID'] : '');
?>
The first time I opened this page was There will be no output because the cookie will not take effect immediately on the current page.
It will be displayed after refreshing.
The above introduces the cookie settings. PHP COOKIE is set as a browser process, including cookie settings. I hope it will be helpful to friends who are interested in PHP tutorials.