PHP sets COOKIE retention time for browser process_PHP tutorial

WBOY
Release: 2016-07-13 17:35:55
Original
939 people have browsed it

For example:

The following is the quoted content:
$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 of the COOKIE variable $USERID.
The problem analysis 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 "pcpchina.com", it means that you must use "pcpchina.com" to access the cookie for it to be effective. In fact, if your If there are many domain names to access this page, then this place can be empty or the domain names accessing this cookie are all under the same domain, then set it to ".pcpchina.com", remember there is a "dot" in front of it

The above program may work if you write it like this:

The following is the quoted content:
$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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508272.htmlTechArticleFor 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...
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!