Cookies were originally designed for CGI programming. However, we can also use JavaScript scripts to manipulate cookies. In this article, we will demonstrate how to use JavaScript scripts to manipulate cookies. (If necessary, I mayArticleDescribes how to use Perl for Cookie management. But if it is not possible, I will teach you how to: take a closer look at CGI. PM. In this CGI package, there is a cookie () function that can be used to create a cookie. However, let's first introduce the nature of cookies.
In JavaScript scripts, a cookie is actually a string attribute. When you read the cookie value, you get a string containing the names and values of all cookies used on the current web page. Each Cookie has four attributes besides the name and value attributes. These attributes are: expires expiration time, Path, domain, and secure security.
Expires-Expiration time. Specifies the life cycle of the cookie. Specifically, the value is the expiration date. This attribute is required if you want to allow the cookie to exist for more than the current browser session time. When the expiration date expires, the browser can delete the cookie file without any impact.
Path-Path. Specifies the web page associated with the cookie. The value can be a directory or a path. If/head/index.html creates a cookie, all the pages in the/head/directory and the pages in any subdirectories under the directory can access the cookie. This means that any page in/head/stories/articles can access the cookie created by/head/index.html. However, what if/zdnn/needs to access cookes set in/head/index.html? In this case, we need to set the path attribute of cookies to "/". When specifying a path, all web pages with the same path in the URL from the same server can share cookies. Now let's look at another example: If you want/head/filters/AND/head/stories/to share cookies, set path to "/head ".
Domain-Domain. Specify the associated web server or domain. The value is a domain name, such as goaler.com. This is an extension of the path attribute. What if we want dev.mycompany.com to access cookies set by bbs.mycompany.com? We can set the domain attribute to "mycompany.com" and the path attribute to "/". FYI: you cannot set the cookie domain attribute to a value different from the domain of the server on which it is set.
Secure-Security. Specify how the cookie value is transmitted 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 null, that is, data is transmitted using an insecure HTTP connection. If a cookie is marked as secure, data is transmitted between it and the Web server over https or other security 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 as secure only ensures that the data transmission process between the cookie and the Web server is encrypted, while the cookie files stored locally are not encrypted. If you want to encrypt the local cookie, you must encrypt the data yourself.