Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the advantages and disadvantages of cookie and session

Shulou Source: shulou.com Published: 2022-05-31 23:46:19 10月12日 Update

This article mainly explains "what are the advantages and disadvantages of cookie and session". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the advantages and disadvantages of cookie and session".

1. Why use session control technology?

Web is implemented through the HTTP protocol, while the HTTP protocol is stateless, so when the same user requests the same page twice, the HTTP protocol will not think that the two requests come from the same user, but will treat them as independent of the two requests (that is, they will separate the two requests), and will think of them as two different user requests. If a user performs a login operation and requests the page again, the HTTP protocol will not assume that the user has logged in before, because it cannot maintain the user's previous login status, so it cannot track and maintain the user's status between different pages.

2. Working principle of Cookie

How cookie works: it is a technology in which fragments of information sent by the server to the client are stored in the memory or hard disk of the client browser. Think of it as a file stored in the browser, which contains some pieces of information about our client (such as login or some other information stored, etc.). This file is stored on the client! ]

3. Advantages and disadvantages of Cookie

The advantage of cookie: because cookie stores information on the client, it will not take up the resources of the server (that is, it will not waste the resources of the server) and will be more efficient. The disadvantage of cookie: it is also because it is stored in the client, because all our information is stored in the client computer, so it is not recommended to save some sensitive and important data in cookie, and users have the right to prohibit the use of cookie. If we disable cookie in the browser, once the user forbids cookie, we have no way to save the user's information.

4. The working principle of session

Store the same data of the user in the server

5. Advantages and disadvantages of Session

The advantage of session: the information is very secure, it is stored on the server side, and it is impossible for the client to get the session data. Disadvantages of session: it will take up the resources of the server (more and more session files may fill the disk one day), and its distribution is also a problem (for example: we may have multiple web servers in the future, but session may be stored in one of them, and the other one cannot be used. In this case, we can use redis, no matter which server we are on, we can call redis's server to achieve information sharing.

Thank you for your reading, the above is the content of "what are the advantages and disadvantages of cookie and session". After the study of this article, I believe you have a deeper understanding of what are the advantages and disadvantages of cookie and session. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Users servers storage services information customers clients files strengths and weaknesses strengths weaknesses logins principles browsers status resources pages learning work Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Shulou Tech Info OPPO Reno Linux macOS