What are the differences between cookies and sessions in web front-end technology

  What are the web front-end technologies? What is the difference between Cookie and Session? Cookie and Session are commonly used technologies in Web programs, and both can be used to track the user's entire session. But what is the difference between them? Next, the editor of Qianfeng will give you a brief introduction.

 

 

  The main purpose

  Cookie was born to solve the problem of HTTP's stateless characteristics that cannot meet the interactive Web. It is mainly used for session state management (such as user login status, shopping cart, game score or other information that needs to be recorded); personalized settings (such as user-defined Settings, themes, etc.); browser behavior tracking (such as tracking and analyzing user behavior, etc.).

  Session is a mechanism used by the server to record the state of the client. It is simpler to use than Cookies, and accordingly increases the storage pressure of the server.

  If the Cookie mechanism is to determine the identity of the customer by checking the "passport" on the customer, then the Session mechanism is to confirm the identity of the customer by checking the "customer list" on the server. Session is equivalent to a client file created by the program on the server. When a client visits, it only needs to query the client file table.

  scenes to be used

  Cookie technology can store information in different browsers, and can realize data sharing under multiple requests. It is divided into temporary cookies and long-term cookies. If a cookie has no expiration date set, then the browser will delete the cookie when it is closed. This cookie is called a temporary cookie; if a cookie has a expiration date, the browser will keep the cookie until the expiration date. This cookie is called a long-term cookie. Cookies.

  Session is a communication state retention mechanism built on Cookie, which can store some user information on the server. After the server creates the Session, it returns the Session id to the browser in the form of a Cookie. As long as the browser is not closed, when you visit the server, it will carry the Session id. If the server finds that the browser comes with the Session id, it will Use the corresponding Session in the memory to serve it.

  What is the relationship between Cookie and Session

  If web front-end programmers encounter the question of "What is the relationship between Cookie and Session" during the interview, they can answer this: Both are produced for the interaction between the client and the server. Among them, Cookie is to write the user's data to the user's browser, while the Session technology writes the user's data into the user's own Session. Session is an object, and its attributes can be of any type (Cookies can only be set as strings). Cookies are stored on the client side, with shortcomings that are easy to forge and insecure. Session is stored on the server side, which consumes server resources. There are two ways to implement Session: Cookie and URL rewriting.

  If you want to learn more about Cookie and Session-related knowledge, or want to quickly advance to the web front-end, you can choose to study professionally, so that you can learn efficiently and get a job quickly.

 

Guess you like

Origin blog.csdn.net/qq_43444478/article/details/112599592