PHP Set cookie retention time for browser process _php tutorial

Source: Internet
Author: User
Tags set cookie setcookie

For example:

The following is the referenced 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, and the next page shows no $userid the cookie variable value.
The problem analysis is as follows:

First of all, set the browser process's "Cookie Expiration Time" value is not the current UNIX timestamp +0, if set as a browser process, the expiration time is set to 0.
Secondly, it is unclear what domain name you used when testing this page, if you set up "pcpchina.com", it means that you must use "pcpchina.com" to access the cookie will be effective, in fact, if your domain name a lot of access to this page, So this place can be empty or the domain name that accesses this cookie is a domain below, then set to ". Pcpchina.com", Remember "dot" in front

The above program may work if you write this:

The following is the referenced content:
$USERID = "Phper";
$CookieTime = 0;
Setcookie ("USERID", "$USERID", 0, "/", "");
Echo (Isset ($_cookie[userid]) $_cookie[userid]:);
?>

The first time you open this page there will be no output, because the cookie does not take effect immediately on the current page.
The refresh will be displayed later.

http://www.bkjia.com/PHPjc/508272.html www.bkjia.com true http://www.bkjia.com/PHPjc/508272.html techarticle For example: The following is the referenced content:? php $USERID = "Phper"; $CookieTime =0; Setcookie ("USERID", "$USERID", Time () + $CookieTime, "/", " Pcpchina.com ");? You will find that after this statement is executed ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.