[Linux Network] The relationship between Cookie and session

Table of contents

1. What is common between Cookie and session

Second, the difference between Cookie and session

2.1、cookie

2.2、session

3. How cookies work

Fourth, the working principle of session


1. What is common between Cookie and session

 Both Cookie and Session are sessions used to track the identity of the browser user.

Second, the difference between Cookie and session

2.1、cookie

  (1) Cookie is a small piece of text saved on the client ; it can be used to save the state information during the user's activities to the client, and the server can obtain this information for processing and tracking the user's state; (2) Cookie does not Safe; (3) Cookies can be stored for a long time; (4) The maximum size of Cookies does not exceed 3KB; (5) Cookies do not occupy server resources.

2.2、session

  (1) Session is an object stored on the server, which is created and maintained by the server; the server creates and maintains a Session object for each session between the client and the server; (2) Session security; (3) Session default Store 30 minutes of data size; (4) Session has no size limit on server performance; (5) Session needs to occupy server resources.

3. How cookies work

  1. The browser sends a request to the server for the first time;
  2. The server creates a cookie, which contains user information, and then sends the cookie to the browser.
  3. When the browser accesses the server again, it will carry the cookie created by the server.
  4. The server distinguishes different users through the data carried in the cookie.

Fourth, the working principle of session

  1. When the browser sends a request to the server for the first time, the server creates a Session and creates a special cookie at the same time, and then sends the cookie to the browser
  2. The browser sends the Nth (N>1) request to the server, and the browser will carry the Cookie object when accessing the server
  3. The server will query the Session object according to the Sessionid of the Cookie, so as to distinguish different users.
     


If there are deficiencies in this article, you are welcome to comment below, and I will correct it as soon as possible.

Guess you like

Origin blog.csdn.net/m0_63198468/article/details/132460636