PHP sets COOKIE retention time as a browser process

Source: Internet
Author: User
PHP sets the COOKIE retention time as the browser process, and read the PHP setting the COOKIE retention time as the browser process. for example, the following is the reference content :? Php $ USERID = "> <LINKhref =" http://www.php100.com//statics/style/headfloor_950_081205.css "type = text/cs

For example:

Reference content is as follows:
$ USERID = "PHPer ";
$ CookieTime = 0;
Setcookie ("USERID", "$ USERID", time () + $ CookieTime, "/", "pcpchina.com ");
?>

You will find that after the statement is executed, there is nothing in the Cookie. the COOKIE variable value $ USERID is displayed on the next page.
The problem is analyzed as follows:

First, set the "Cookie expiration time" of the browser process. this value is not the current Unix timestamp + 0. if it is set to a browser process, set the Expiration Time to 0.
Secondly, it is unclear what the domain name is when you test this page. if you set "pcpchina.com", it means that you must use "pcpchina.com" to access the cookie to make it valid, in fact, if many of your domain names access this page, the domain name that can be empty or access this cookie is under the same domain, then set it to ".pcpchina.com ", remember that there is a "dot" in front"

The above program may be valid if you write it like this:

Reference content is as follows:
$ USERID = "PHPer ";
$ CookieTime = 0;
Setcookie ("USERID", "$ USERID", 0 ,"/","");
Echo (isset ($ _ COOKIE ['userid'])? $ _ COOKIE ['userid']: '');
?>

When this page is opened for the first time, no output is generated because the cookie does not take effect immediately on the current page.
It will be displayed after refresh.

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.