Cookie settings PHP COOKIE is set to the browser process

WBOY
Release: 2016-07-29 08:40:07
Original
1244 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!