Introduction to cookies

Introduction to cookies

Cookies Overview

Cookies are small text files used in web browsers to store user information. The size of cookies is usually limited within 4KB (different browser kernels may have slight differences or have a higher limit for a single domain name). When you visit a website, the website may create a cookie on your computer so that it can recognize your browser and store some information about you, such as your preferences and login credentials (authentication). This information can help the website provide better user experience and personalized services. For example, cookies can store the credentials of your account password, which can be directly provided to the website without entering the account password every time. Cookies can be divided into session cookies and persistent cookies. Session cookies are stored in the memory of the user's browser and are automatically cleared when the user closes the browser. Persistent cookies, on the other hand, are stored on the hard disk of the user's computer, even if the browser is closed, they still exist, and can continue to be used the next time the website is visited. Persistent cookies must have an expiration time set to prevent them from taking up disk space all the time. Persistent cookies remain until they expire or are manually deleted.

It should be noted that cookies are a technology that is easy to be abused. Malicious websites can use cookies to track user behavior and collect personal information. Because cookies can be used to track users' network activities, users are advised to remain vigilant when using the Internet and pay attention to the protection of their own information.

The cookie content format is a key-value pair of "name=value". It consists of a name (name) and a value (value), which are connected by an equal sign (=), and multiple cookies are separated by a semicolon (;). For example, "username=john; language=en-US; session-id=123456". In addition to the name and value, a cookie can also include optional attributes such as expiration time (expiration time), domain name, path, security, etc.

View cookie method

You can use the developer tools of your browser to view the cookie information set by the current website. Different browsers may operate slightly differently.

The following take Google Chrome and Microsoft Edge browsers as examples

Open the Chrome browser and navigate to the website you want to view cookies. Press F12 to open the developer tools window, click the "Applications" tab on the top toolbar. In the left navigation panel, expand the "Storage" tab and select "Cookies" to see the Cookies table. See the picture below:

As can be seen from the cookie table, the composition of the cookie: name (Name), value (Aalue), domain (Domain), path (path), expiration/maximum period (Expires), security (Secure), etc. More introductions can be found at https://learn.microsoft.com/zh-cn/microsoft-edge/devtools-guide-chromium/storage/cookies

JavaScript manipulation cookies

See "How JS Creates, Reads, and Deletes Cookies"   https://juejin.cn/post/6844903933320790024
I won't say much here.

Guess you like

Origin blog.csdn.net/cnds123/article/details/131082637