What is a Cookie?

Cookie is actually a short piece of text information. The client requests the server. If the server needs to record the user status, it issues a Cookie to the client browser using response. The client will save the Cookie, when the browser request the website, the browser will request the URL together with the Cookie submitted to the server, the server checks the Cookie, in order to identify the user status, the server can also modify the content of the Cookie according to the demand;

 

Advantages and disadvantages of Cookies

Advantages:

1. High scalability and availability

You can control the size of session objects stored in cookies;

Through encryption and secure transmission technology (SSL), reduce the possibility of Cookie cracking;

Only store insensitive data in cookies, there will be no significant loss if stolen;

Control the Cookie’s lifetime so that it will not be valid forever, and the thief may get an expired Cookie;

Text-based lightweight structure;

Cookies are stored on the client and read by the server after being sent;

 

Disadvantages:

1. Limit the number and length of cookies

Each domain can have a maximum of 20 cookies. The length of each cookie cannot exceed 4KB; otherwise, the cookie will be truncated.

2. The security

Cookies can be intercepted or tampered with. If the Cookie is intercepted, that person can get all session information

3. Some states cannot be saved on the client

Example: To prevent repeated submission of forms, save the counter on the server side, if the counter is saved on the client side, it is useless.

 

Extension:

The difference between cookies and sessions

1. Cookie data == customer’s browser

Session data == server

2. Cookies are not very secure. Others can analyze cookies stored locally and cheat cookies

3. The session will be stored on the server for a certain period of time. When the number of accesses increases, the performance of the server will be occupied

4. Single Cookie data cannot exceed 4K. Many browsers limit the maximum number of cookies stored on a site to 20

 

Advice:

Important information such as login information is stored in the session

Other information can be placed in cookies if you want to keep it