Home > Back-end >  do browsers have an address for receiving cookies from the sites and how do websites know that i vis
do browsers have an address for receiving cookies from the sites and how do websites know that i vis

Time:08-19

1 - How do websites send cookies to the browser ?

2 - How does the website know the browser address to send it cookies ?

3 - How do websites detect visits ?

4 - How does the browser send cookies back to the website ?

CodePudding user response:

Cookies aren't just 'sent', this could be done, in javascript for example (through an api or user actions), but normally is done on first load.

1. Cookies are set in HTTP headers.

You receive these when you first load the page. You can inspect this in the "network" tab when you press F12 in your browser. Click on an item, and check out it's headers. They look something like this: enter image description here

  1. They are sent along with the document, HTTP isn't a stream, to keep it simple, it's just UTF-8 text files.

3. Whenever you visit a website, you send a request to the server.

When the server receives the request (Along with maybe headers, and extra data if you submit a form), a server can then preform some logic with the request, and extract data from the request headers and body, or maybe even set a cookie, that tells the server you've visited! Anyways here is an example of a request: enter image description here

4. Whenever you send that request, the headers, which include your cookies get sent along with it.

They look like: enter image description here

Disclaimer:

All images are from google.

  • Related