“This is the first day of my participation in the Gwen Challenge in November. See details of the event: The last Gwen Challenge in 2021”.

preface

Today we’re going to talk about client-side storage, and cookies are definitely in mind. With the advent of Web applications came the need to store user information directly on the client side. The idea behind this is sound: the messages that are relevant to a particular user are self-generated on tago’s machine. Whether it’s login information we’re going to talk about client-side storage today, cookies are definitely in mind. With the advent of Web applications came the need to store user information directly on the client side. The idea behind this is sound: the messages that are relevant to a particular user are self-generated on tago’s machine. Whether it’s login information, personal preferences, or other data, the Web application provider needs to have a way to store it on the client side. The first solution to this problem is cookies, the canonical definition of cookies. Today, the canonical definition of cookie was invented by the old Netscape company, by a document called Persistent Client State: HTTP Cookies. Today, cookies are just an option for storing data on the client side.

A cookie is introduced

HTTP cookies, also known as cookies, were originally used by clients to store session information. This specification requires that the server respond to an HTTP request by sending a set-cookie HTTP header containing session information. For example, here is an HTTP response containing this header:

  • HTTP/1.l 200 OK
  • Contenc-CYpe: text /html
  • Set-CO0k1e: name=value
  • other-header: otner-header-value

The cookie “name” with a value of “value “, both the name and the value are sent through the URL. The HTTP response sets a name and the browser stores the session information and returns the HTTP header cookie to the server on every subsequent request, for example:

  • GET/index. JSL HTTP / 1.1
  • Cookie: name=value
  • other-header: other-header-value

This additional information sent back to the server can be used to uniquely identify the client that sent the request.

The composition of the cookie

A cookie in a browser is made up of the following parameters.

  • Name: the name that uniquely identifies the cookie myCookie and L myCookie are the same name. Cookie names are case insensitive. However, because some server software may treat them this way. Therefore, in practice it is best to treat cookie names as case sensitive. Cookie names must be URL-encoded.

  • Value: string value stored in cookie. This value must be URL-encoded.

  • Domain: the domain in which the cookie is valid. All requests sent to this domain will contain the corresponding cookie. This value may contain subfields (such as www.WTOx.com) or may not be included (such as www.wrOx.com means that all subfields specified by wrox.co are valid). If unknown, the default is the domain to set the cookie.

  • Path: The cookie is sent to the server only if this path is included in the request URL. For example, you can specify that cookies can only be accessed by www.wrox.com/books/, so pages under www.WrOx.cOm/ will not be sent cookies, even if the same domain is requested.

  • Expiration time: Indicates when the timestamp of the cookie is deleted (that is, after what time it is not sent to the server). By default, all cookies are deleted after the browser session ends. However, you can also set the specific time at which cookies are deleted. This value is in GMT format (Wdy, DD-MON-YYYY HH:MM:SS GMT) and is used to specify the time when the cookie is deleted. So that even if it’s closed,

  • Security flag: When set, cookies will only be sent if an SSL secure connection is used, and requests to www.wrOx.com will not. For example, a request to www.WrOx.com sends a cookie, but a request to www.WrOx.com does not.

These parameters are separated by a semicolon followed by a space in the set-cookie header, for example:

  • HTTP / 1.1200 OK
  • Content-type: text/htm
  • Set-Cookie: name=value; expires=Mon, 22-Jan-07 07:10:24Other-header: other-header-value

This header sets a cookie named “name “that expires at 7:10:24, January 22, 2007, for WWW.wrOX.com and other Wrox.com subfields such as p2p.wrox.com.

The security flag Secure is the only non-name/value pair in the cookie, and you only need one secure. Such as:

  • HTTP / 1.1200 OK
  • Content-type: text/htm.
  • Set-Cookie: name=value
  • domain=.wrox.cOm;
  • path=/; secur
  • Other-header: other-header-value

The cookie created here is valid for the wrOx.com domain and all pages in that domain (specified by path=/). However, this cookie can only be sent on an SSL connection because the secure flag is set. Cookies should be included in the request. Remember that the field, path, expiration time, and Secure flag are used to tell the browser what value pairs are. These parameters are not sent to the server along with the request, only the cookie’s name/header is separated by a semicolon and a space.