A brief analysis of path and domain_jquery in cookies

Source: Internet
Author: User

path– path. Specifies the Web page associated with the cookie.

The value can be a directory, or a path.

If http://www.jb51.net/test/index.html establishes a cookie, then all pages in the http://www.jb51.net/test/directory, This cookie is accessible to pages in any subdirectory below the directory.
This means that any page in the HTTP://WWW.JB51.NET/TEST/TEST2/TEST3 can access cookies created by http://www.jb51.net/test/index.html.
But what if http://www.jb51.net/test/needs to access the Cookes of http://www.jb51.net/test/index.html settings?

At this point, we will set the cookie's path attribute to "/". When you specify a path, all Web pages that come from the same server with the same path in the URL can share cookies.

domain– domain. Specifies the associated Web server or domain.

Values are domain names, such as Www.jb51.net. This is an extension of the path Path property. What if we want www.jb51.net to be able to access cookies set by bbs.china.com? We can set the domain property to "china.com" and set the Path property to "/".

secure– safe. Specifies how the value of the cookie is passed between the user and the Web server over the network.

The value of this property is either "secure" or empty. By default, this property is null, which means that data is passed using an unsecured HTTP connection. If a cookie is marked secure, it passes data between it and the Web server through HTTPS or other security protocols. However, setting the secure attribute does not mean that other people cannot see cookies stored locally on your machine. In other words, setting the cookie to secure only guarantees that the cookie is encrypted with the data transfer process between the Web server, while the locally stored cookie file is not encrypted. If you want to encrypt the local cookie, you have to encrypt the data yourself.

expires– Expiration time. Refers to the lifetime of the cookie, which is exactly the expiration date.

You must use this property if you want the lifetime of the cookie to exceed the session time of the current browser. When the expiration date is passed, the cookie file is automatically deleted by the browser.

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.