Analyze Path and domain in Cookie

  • 2020-03-30 00:58:13
  • OfStack

Path. Specifies the WEB page associated with the cookie.

The value can be a directory or a path.

If a cookie is established in / / www.jb51.net/test/index.html, then at / / www.jb51.net/test/ all the page in the directory, as well as the directory page in any subdirectory below can access the cookies.
That is to say, in / / www.jb51.net/test/test2/test3 any page can access / / www.jb51.net/test/index.html cookies.
However, if the need to visit / / www.jb51.net/test/index.html / / www.jb51.net/test/ set the cookes, what should I do?

At this point, we set the cookies' path property to "/". When specifying a path, cookies can be Shared on all WEB pages that come from the same server and have the same path in their URL.

Domain � Domain. Specifies the associated WEB server or domain.

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

Secure security. Specifies how the value of the cookie is passed between the user and the WEB server over the network.

The value of this attribute is either "secure" or null. By default, this property is null, meaning that the data is passed over an insecure HTTP connection. If a cookie is marked as secure, data is passed between it and the WEB server over HTTPS or some other security protocol. However, setting the secure attribute does not mean that others cannot see cookies that are locally stored on your machine. In other words, setting the cookie to secure only ensures that the data transfer between the cookie and the WEB server is encrypted, while the cookie file saved locally is not. If you want local cookies to be encrypted, you'll have to encrypt the data yourself.

Expires. Refers to the lifetime of a cookie, specifically the expiration date.

If you want the cookie to last longer than the current browser session, you must use this property. When the expiration date passes, the browser will automatically delete the cookie file.


Related articles: