First, set the "Cookie expiration time" of the browser process. this value is not the current Unix timestamp + 0. if it is set to a browser process, set the Expiration Time to 0. Cookie
For example:
The code is as follows:
$ USERID = "PHPer ";
$ CookieTime = 0;
Setcookie ("USERID", "$ USERID", time () + $ CookieTime, "/", "btcuxiao.com ");
?>
You will find that after the statement is executed, there is nothing in the Cookie. the COOKIE variable value $ USERID is displayed on the next page.
The problem is analyzed as follows:
First, set the "Cookie expiration time" of the browser process. this value is not the current Unix timestamp + 0. if it is set to a browser process, set the Expiration Time to 0.
Secondly, it is unclear what the domain name is when you test this page. if you set "btcuxiao.com", it means that you must use "btcuxiao.com" to access the cookie to make it valid, in fact, if many of your domain names access this page, the domain name that can be empty or access this cookie is under the same domain, then set it to ".btcuxiao.com ", remember that there is a "dot" in front"
The above program may be valid if you write it like this:
The code is as follows:
$ USERID = "PHPer ";
$ CookieTime = 0;
Setcookie ("USERID", "$ USERID", 0 ,"/","");
Echo (isset ($ _ COOKIE ['userid'])? $ _ COOKIE ['userid']: '');
?>
When this page is opened for the first time, no output is generated because the cookie does not take effect immediately on the current page.
It will be displayed after refresh.