For example:
The following is the quoted content:
<?php
$USERID="PHPer";
$CookieTime=0;
setcookie("USERID", "$USERID", time()+$CookieTime,"/","pcpchina.com");
?>
You will find that after this statement is executed, there is nothing in the Cookie. When you go to the next page, it will be displayed that there is no value for the COOKIE variable $USERID.
The problem analysis is as follows:
First, 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 "pcpchina.com", it means that you must use "pcpchina.com" to access the cookie for it to be effective. In fact, if your domain name has many visits For this page, then this place can be empty or the domain name accessing this cookie is under the same domain, then set it to ".pcpchina.com". Remember that there is a "dot" in front of
the above program. If you write like this, it may Will be effective:
The following is the quoted content:
<?php
$USERID="PHPer";
$CookieTime=0;
setcookie("USERID","$USERID",0,"/","");
echo(isset($_COOKIE['USERID'])?$_COOKIE['USERID']:'');
?>
There will be no output when you open this page for the first time, because the cookie will not take effect immediately on the current page.
It will be displayed after refreshing.