Briefly describe the difference, advantages and disadvantages of Cookie and Session


Author: The initial appearance of
the link: https://blog.csdn.net/zhang_8626
Source: CSDN
copyright reserved by the authors. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.


Write picture description here
The difference between cookie and session:
1. The cookie data is stored on the client's browser, and the session data is stored on the server.
2, cookie is not very safe, people can analyze stored locally COOKIE COOKIE cheat and
take into account security should use the session.
3. The session will be saved on the server for a certain period of time. When accessing the increase would be more take up the performance of your server
take into account mitigating server performance, you should use COOKIE.
4. The data saved by a single cookie cannot exceed 4K. Many browsers limit a site to save a maximum of 20 cookies.
The connection between cookie and session:
Session works through cookies. You can consider storing important information such as login information as session. If you need to keep other information, you can put it in cookies.

In shopping websites, the Unicom session_id of the product that the user added to the shopping cart is usually recorded in the database. When the user visits again, the last time the user added to the shopping cart can be found through the sessionid. Because the sessionid is unique, it can be searched based on the record in the database.

Guess you like

Origin blog.csdn.net/zhang_8626/article/details/81636161