Summarize the advantages and disadvantages of cookies and sessions

远方*
Release: 2023-03-15 17:06:02
Original
1390 people have browsed it

1. Why use session control technology?

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

2. Working principle of Cookie

The working principle of cookie: It is a piece of information sent by the server to the client and stored in the memory or hard disk of the client's browser. [It can be thought of as a file stored in the browser. This file contains some fragments of information on our client (such as login or other stored information, etc.). It is a file. This file is stored in the client. That’s right! ! ! 】

3. Advantages and Disadvantages of Cookie

Advantages of cookie: Because cookie stores information on the client, it does not occupy the server's resources (that is, it does not waste the server's resources) , the efficiency will be higher. Disadvantages of cookies: It is also because it is stored on the client. Since all our information is stored on the client computer, it is not recommended to save some sensitive and important data in cookies, and users have the authority to prohibit the use of cookies. If we disable cookies in the browser, once the user disables cookies, we have no way to save the user's information.

4. Working principle of session

Storing the same data of users in the server

5. Advantages and disadvantages of Session

Advantages of session: The information is very secure and is stored on the server side. It is impossible for the client to get the session data. Disadvantages of session: It will occupy server resources (more and more session files may fill up 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 It is stored in one of them, but the other one cannot be used. In this case, we can use redis. No matter which server it is, we can call the redis server to achieve information sharing).

Recommended: "PHP Video Tutorial"

The above is the detailed content of Summarize the advantages and disadvantages of cookies and sessions. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!