The composition of web cookies and analysis of related attributes

Source: Internet
Author: User
Tags date domain
cookie| Web page

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 manipulate cookies using JavaScript scripts. (if there is a need, I'll probably explain how to use Perl for cookie management in future articles.) But if it is not, then I will teach you one hand: Take a closer look at cgi.pm. There is a cookie () function in this CGI package that you can use to create cookies. However, let us first introduce the nature of cookies.

In JavaScript scripts, a cookie is actually a string property. When you read the value of the cookie, you get a string that contains the name and value of all cookies used in the current Web page. Each cookie has four properties, in addition to the name and value values. These properties are: Expires expiration time, path path, domain field, and secure security.

  Expires – Expiration time. Specifies the lifetime of the cookie. The exact value is the expiration date. You must use this property if you want the lifetime of the cookie to exceed the current browser session time. When the expiration date is passed, the browser can delete the cookie file without any effect.

   Path-paths. Specifies the Web page associated with the cookie. The value can be a directory, or a path. If/head/index.html creates a cookie, then all pages in the/head/directory, as well as pages in any subdirectory below the directory, can access the cookie. This means that any page in the/head/stories/articles can access cookies created by/head/index.html. But what if/zdnn/needs access to the Cookes of/head/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. Now look at another example: if you want/head/filters/and/head/stories/to share cookies, set the path to "/head".

   domain-domains. Specifies the associated Web server or domain. Values are domain names, such as goaler.com. This is an extension of the path Path property. What if we want dev.mycompany.com to be able to access cookies set by bbs.mycompany.com? We can set the domain property to "mycompany.com" and set the Path property to "/". FYI: You cannot set the cookie domain attribute to a different value than the domain of the server where it is set.

   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.







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.