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 / /, then at / / 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 / / any page can access / / cookies.
However, if the need to visit / / / / 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 This is an extension of the path property. What if we want to be able to access the cookies set by We can set the domain property to "" 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: