The HTTP protocol is stateless. But for a commercial website, it needs to maintain session information between different pages.
If the user needs to jump to the page during the registration process of thewebsite, but make sure that the information filled in before is not lost.
In this case, Almost all website designers use The The syntax used to send When giving to the non-existent Because If the user wants to read It is important to note that only before the server has downloaded any data to the browser can the browser communicate with 1.``Expires`` attribute: this property is used to give 2.``Domain`` attribute: this property defines the 3.``Path`` attribute: defined 5.``Name=Value`` : You can create a file named Next, let’s go back to this page and find Parameters. Description Name Specifies the name of the cookie. Value Specifies the value of cookie. Expire Specify the period of validity of the cookie. Path Specifies the server path for cookie. Domain Specifies the domain name of the cookie. Secure Specifies whether cookie is transmitted over a secure HTTPS connection. Cookie help us solve the problem. 6.38.1. How does Cookie work? #
Cookie in website design. Because they all want to provide users who browse the website with a more friendly and cultural browsing environment, and at the same time collect visitors’ information more accurately. 6.38.2. Write and read #
Cookies collection is attached to the Response object and Request object, which needs to be preceded by Response or Request . Cookies to clients is usually: Cookies collection is set, it is created on the client, if the Cookies already exists, it will be replaced. Cookies are sent to the client as part of the header information for HTTP transmission, so the code for sending Cookies to the client is usually placed before the tags in the HTML file sent to the browser. Cookies , you must use the Request object’s Cookies collection, which is used by: Server carry on Cookies collection of data exchange, once the browser starts to receive``Server`` downloaded data Cookies . The data exchange is stopped, and to avoid errors, add response.Buffer=True . 6.38.3. Properties of the collection #
Cookies set a deadline within which you can call the saved Cookies as long as you open theweb page. If the deadline has passed, Cookies is automatically deleted. Such as: setting Cookies valid until April 1, 2004, when it will be automatically deleted. If Cookies validity period isnot set, the life cycle starts from opening the browser to the end of closing the browser, the life cycle will end after each run, and the next run will start again. Cookies uniqueness of transmitting data. If only a certain Cookies transmit to``_blank”>`` for Sohu’s home page, you can use the following code: Cookies send only the specified path request, if Path property is not set, the default path of the application is used. Secure attributes: specify in Cookies can it be read by the user. Cookies is set and retrieved in the form of key-value pairs. 6.38.4. Dealing with Cookies in Ruby #
cookie and store text information, send theinformation to the browser, and call the CGI.out to set up the head of cookie .Example #
#!/usr/bin/rubyrequire"cgi"cgi=CGI.new("html4")cookie=CGI::Cookie.new('name'=>'mycookie','value'=>'Zara
Ali','expires'=>Time.now+3600)cgi.out('cookie'=>cookie)docgi.head+cgi.body{"Cookie
stored"}end
cookie value, as follows:Example #
#!/usr/bin/rubyrequire"cgi"cgi=CGI.new("html4")cookie=cgi.
cookies['mycookie']cgi.out('cookie'=>cookie)docgi.head+cgi.body{cookie[0]}end
CGI::Cookie Object instantiation includes the following parameters: