How to correctly use the cookie path in detail

Source: Internet
Author: User

Original address: http://java-zone.org/1052.html

The cookie has path--path, which indicates which path the file has permission to read from the cookie.

Path should end with "/", cookie of the same name, different path, different cookie

Document.cookie = "n1=1; path=/path/";
Document.cookie = "n1=2; Path=/path ";
Document.cookie = "n1=3; path=path/";

As the above code, the first two sentences relative to the site root directory of the Web page, the third sentence is used relative to the current directory path.

The first sentence and the second sentence are different, although they express the same permissions, but because the path string different, will form two of the same name of the cookie, easy to cause confusion, we recommend the use of the first sentence of this format, because the system default is also "/" end.

So if the above is three cookies, there is no overlap between them.

The Path property value is case-sensitive and should match the input of the address bar in the browser

Document.cookie = "n1=1; path=/path/";
Document.cookie = "n1=2; path=/path/";

This is a two different cookie, because the Path property value is different case, if we enter path in the address bar, then read the first N1, if we enter path, then read the second N1

Path is not readable

As with expires, path is only writable and unreadable.

Path cannot be changed

Unlike expires, if we try to change path, we actually write another cookie instead of changing the path value.

Path Permission is inherited

If the/test/directory is specified to have permission to read a cookie, the directory/test/t/under/test/also has permission to read the cookie.

How to correctly use the cookie path in detail

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.