Home > Web Front-end > JS Tutorial > A brief analysis of Path and domain_jquery in Cookies

A brief analysis of Path and domain_jquery in Cookies

WBOY
Release: 2016-05-16 17:08:40
Original
1249 people have browsed it

Path – path. Specify the WEB page associated with the cookie.

The value can be a directory or a path.

If http://www.jb51.net/test/index.html creates a cookie, then all pages in the http://www.jb51.net/test/ directory, and any sub-directories under this directory All pages in the directory can access this cookie.
This means that any page in http://www.jb51.net/test/test2/test3 can access the cookie created by http://www.jb51.net/test/index.html.
However, what should we do if http://www.jb51.net/test/ needs to access the cookies set by http://www.jb51.net/test/index.html?

At this time, we need to set the path attribute of cookies to "/". When specifying a path, all WEB pages that come from the same server and have the same path in the URL can share cookies.

Domain – domain. Specify the associated WEB server or domain.

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

Secure – safe. Specifies how cookie values ​​are passed between the user and the WEB server over the network.

The value of this attribute is either "secure" or empty. By default, this attribute is empty, which means an insecure HTTP connection is used to transfer data. If a cookie is marked as secure, then data is transferred between it and the WEB server through HTTPS or other secure protocols. However, setting the secure attribute does not mean that others cannot see the cookies saved locally on your machine. In other words, setting the cookie to secure only ensures that the data transmission process between the cookie and the WEB server is encrypted, and the cookie file stored locally is not encrypted. If you want local cookies to be encrypted, you have to encrypt the data yourself.

Expires – Expiration time. Refers to the cookie's lifetime, specifically the expiration date.

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

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template