When setCookie () is used, the Cookie cannot be saved if the domain name is specified as "localhost". why?

Source: Internet
Author: User
When setCookie () is used, the Cookie cannot be saved if the domain name is specified as "localhost". why ?? Found during local testing. In this way, you can set the Cookie: PHPcodesetCookie (name [1], yy1, time () + 3600,); setCookie (name [2], yy2, time () + 3600 using setCookie () when the domain name is specified as "localhost", the Cookie cannot be saved. why ??
Found during local testing.

In this way, you can set the Cookie:
PHP code
      setCookie('name[1]', 'yy1', time() + 3600, '/');    setCookie('name[2]', 'yy2', time() + 3600, '/');


This will not work:
PHP code
      setCookie('name[1]', 'yy1', time() + 3600, '/', 'localhost');    setCookie('name[2]', 'yy2', time() + 3600, '/', 'localhost');


Why? Is the parameter "localhost" incorrect ???

Thank you!

------ Solution --------------------
When working on localhost the cookie-domain must be set to "" or NULL or FALSE
------ Solution --------------------
Discussion

When working on localhost the cookie-domain must be set to "" or NULL or FALSE

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.