Cookies are a solution to one of the legacy problems of the http specification. This problem lies in the inconsistency of the connection between the client and the server, as with an ftp or telnet session, i.e. a separate request is sent for each document (or file) when transmitted over the http protocol.
Including a cookie in the http protocol gave a partial solution to this problem.
A cookie is a small piece of information that the server sends to the client. The client (browser) will store this information and pass it to the server with every request as part of the http header. Some cookies are stored for only one session, they are deleted after closing the browser.
Others, set for a certain period of time, are written to the file. This file is usually named 'cookie.txt'. What can you do with a cookie?
Cookies themselves cannot do anything, they are just some information. However, the server can detect the information contained in the cookies. For example, in the case of authorized access to something through www, the login and password are stored in cookies during the session, which allows you not to enter them when requesting each password-protected document. Another example: cookies can be used to build personalized pages. The most common occurrence is that on some server you are asked to enter your name, and every time you go to the first page of this server, they write to you something like "hello, your_name!". The use of cookies is also often used to build the ordering function in online stores, such a kind of virtual shopping cart, as in an ordinary real supermarket.