JS related operations on the cookie

Before LocalStorage only been used to save the user's login information, today to use the following cookie, feel its characteristics.

First po Case:

https://codepen.io/Kiznaiver1998/pen/mNOMVy

This implementation is the basis for a scene, if the user has landed and is remember your password, then enter the user name password on your own, and will own cache last login user name and password. Of course, this case for passwords stored in plain text or not safe, in practice, should be added md5 encryption and the like. And cookie is generally used to record user preferences and determine whether the landing too.

So we know that cookie is saved string, the string is written is written, the query string is first split into an array using the split, then split to obtain the target value.

Its format is a "key = value; key = value;" like this.

For the last cookie read on MDN / writer is also a strong Amway:

https://developer.mozilla.org/zh-CN/docs/Web/API/Document/cookie

Po then a pen-related questions:

cookie and session are used to do, what relationship

cookie used to store user information on the client, session to the server to store user data, they can be used to track user state.

2. For safety it is, session than important information stored in the client's cookie for security, user authentication and other general store in the session, and cookie can also improve its security through encryption

3. For the life cycle is, cookie permanently stored prior to use scripts or manually delete the user, up to 4KB, and save the session during the session, visit the increase will increase the burden on the server

4.session implementation requires the support of cookie: session-dependent session ID to achieve, and session ID stored in the cookie.

5.session files can be stored on the server, database or memory

Support save each session object, cookie save only the string.

Guess you like

Origin www.cnblogs.com/kiznaiver1998/p/11256713.html