A detailed introduction to path storage when storing cookies in php

Source: Internet
Author: User
In the past, the path parameter was not used when storing cookies. In the recent development, the path parameter was used to determine the storage path. The results were not obtained at the beginning, at the end, I had a detailed look at the introduction of the path parameter before I realized it. I would like to share a few small examples. If this is not very clear, you can test it on your own machine. Se

In the past, the path parameter was not used when storing cookies. In the recent development, the path parameter was used to determine the storage path. The results were not obtained at the beginning, at the end, I had a detailed look at the introduction of the path parameter before I realized it. I would like to share a few small examples. If this is not very clear, you can test it on your own machine. Se

In the past, the path parameter was not used when storing cookies. In the recent development, when storing cookies, the path parameter was used to determine the storage path. At the beginning, no value was obtained, at the end, I had a detailed look at the introduction of the path parameter before I realized it. I would like to share a few small examples. If this is not very clear, you can test it on your own machine.

Setcookie. php (Path: localhost/Test):

(1): When the path parameter is not included:

Setcookie ('testcookie ', 'cookievalue', time () + 86400 );

Print_r ($ _ COOKIE ['testcooker']);

In this case, the value can be obtained on the setcookie. php page.

(2): When the path parameter is included:

Setcookie ('xiaokang ', 'cookievalue', time () + 86400 ,'/Test/mycookie');

Print_r ($ _ COOKIE ['xiaokang ']);

In this case, in setcookie. phpThe value cannot be obtained on this page. Why?

Explanation: although the page url for cookie setting is not necessarily/Test/mycookie must startThe cookie is returned only when the page starting with/test/mycookie is displayed.

Getcookie. php :( its path is localhost/Test/mycookie/Getcookie. php)

Print_r ($ _ COOKIE); // The value can be obtained here.

NOTE: If localhost is added during cookie storage, localhsot must be added during cancellation, for example, setcookie ('xiaokang ', '', time ()-3600 ,'/Test // mycookie ', localhost);

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.