Sobes.tech
Intern

What are cookies?

sobes.tech AI

Answer from AI

Cookies are small pieces of data stored in the user's browser, which the web server sends when visiting a web page.

Used for:

  • User identification: Remembering login.
  • Personalization: Saving user settings (language, theme).
  • Tracking: Analyzing user behavior on the site.

Types of cookies:

  • Session: Stored until the browser is closed.
  • Persistent: Stored until the set expiration date.

The server sets a cookie using the Set-Cookie header:

HTTP/1.1 200 OK
Content-type: text/html
Set-Cookie: user_id=12345; Expires=Wed, 21 Oct 2015 07:28:00 GMT; HttpOnly

The browser sends the cookie to the server with the Cookie header:

GET /index.html HTTP/1.1
Host: example.com
Cookie: user_id=12345; session_token=abcde
What are cookies? — Node.js - sobes.tech