How does a Cookie work?

There are two possibilities for how cookies can function on a website:
1. A cookie can be transmitted via the header for requests and responses via HTTP. Cookies are created in the client when an additional cookie line with the HTTP headers is transferred when a website is accessed.
2. A cookie can be generated locally by JavaScript, Java or a similar scripting language and thus transferred. The respective script is always located in the website which is transmitted by the server.

Cookie information is then stored locally in the browser, usually in a cookie text file. When the web server is subsequently accessed again, only those cookies that have the same domain as the web server are selected by the client browser. This cookie data is then transferred in the header of the web access, whereby they are sent back to the web server from which they once originated.

In general, cookies can be transferred with any transmitted file, including image files or any other file type. This also applies to embedded elements (e.g. advertising banners) from other servers, whereby a single website can lead to several cookies from different servers.