The HTTP cookies or simply cookies are used by the websites to store different information inside your browser. There are many use cases associated with cookies. But before we go into that, let’s take a look at what it is first.
An HTTP cookie is a small piece of data created by the web server in the user’s browser. It is used for user identification and to improve your web browsing experience. The data inside a cookie has an ID that is unique to you and your computer. This ID helps the server know who the user is to send the data accordingly.
Since HTTP is a stateless protocol, the browser and the server needs to main user sessions. Otherwise, they will be signed out every time they close the tab. These sessions are now maintained through cookies.
The server sends a message to the browser containing user information. It is stored as a cookie and later sent back to the server when the user accesses the website. The server uses the cookie information to retrieve the user session from the session database. This is how user sessions are maintained.
Cookies can also be used to track users’ browsing activity to serve them target ads. For instance, if you are searching about cars on some websites, you may see ads about cars on some media websites later.