2
When you set a cookie, this is a request for the client (the browser) to store this information in its cookie storage.
Highly simplified, it works like this:
- You tell your code, set a cookie.
- Your code tells the browser, hey set this cookie.
- Browser says, okay its set.
- On the next request, browser will send the cookie back to you.
It will be available for reading on any requests after the request where you set it. So when you refresh the page, the cookie will be “readable” by your code.
Source:stackexchange.com