HTTP stateless design with cookies and session

Source: Internet
Author: User
Tags session id

Stateless means that any Web request must be completely isolated from other requests, and when requested, the request itself contains all the information required by the corresponding end for that request.

1. The callee does not save parameters because parameter logic is not considered

State logic design by user to save state

HTTP is a stateless design, and some SDK designs can also be stateless.


2. While some requirements need to be interactive and require a state of

Such as:

A. form (form);

B. The client's script processing, DOM processing and other functions;

C. Server CGI (Common Gateway Interface) to handle dynamic requests including form submissions.


Interaction is a need to go through, a practical example is that the simple shopping cart program also need to know what the user chose before the product.


This Web application, in which the client interacts dynamically with the server, requires state.

Workaround:

Two techniques for keeping the HTTP connection state are created, one is a cookie and the other is a session.

A cookie is a solution to a client's saving state, and a cookie is a special message that is sent to the client by the server, which is stored as a text file on the client, and then each time the client sends a request to the server, the special information is brought. Cookies are usually placed in the HTTP header. such as user ID, user name, user's identity information, user school, user company, and so on. Of course, the server will also retain these cookie information, and can add additional attributes to these cookies, such as expiration time and so on.


The session is a solution for the server to keep the state. a series of interactions between the client browser and the server is called a session, which contains not only the duration of the session, but also the operation, as well as the storage space that the server has opened up for the client, in which the information stored is used to hold the state. when the server receives a client request, it generates a unique session ID for the session, and after the session is created, it can invoke the session-related method to add content to the session, which is only stored in the server. Only the session ID is sent to the client, and when the client sends the request again, the session ID is taken, and the server accepts the request and then finds the corresponding session based on the session ID, which is used again. This allows the user to maintain the previous state or request.


And useragent is a device-related, hardware and software information. System-related, related to each URL, but not user-dependent. is to get the server to get this information and to better fit the requests. such as version information, time zone, browser type, and so on.

HTTP stateless design with cookies and session

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.