PHP COOKIE set as browser process_PHP tutorial

WBOY
Release: 2016-07-21 15:46:17
Original
669 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. 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, directly set the expiration time to 0. Can.
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 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 ".btcuxiao.com", remember there is a "dot" in front
If the above program If you write it like this, it may work:
Copy the code The code is as follows:

$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 cookies do not It takes effect immediately on the current page.
It will be displayed after refreshing.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320178.htmlTechArticleFor example: Copy the code as follows: ?php $USERID="PHPer"; $CookieTime=0; setcookie(" USERID", "$USERID", time()+$CookieTime,"/","btcuxiao.com"); ? You will find that after this statement is executed...
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!