How the Web Remembers You

When you visit a website and it remembers who you are, keeps you logged in, or saves items in your shopping cart, it’s not magic. The browser is storing small bits of data that help the site recognize you next time.

Let’s break down the three main ways the web “remembers” things:

  • Cookies
  • Sessions
  • Local Storage

The web is built on HTTP, which is stateless. That means each time you visit a website or load a new page, the site doesn’t automatically remember anything about your previous visit.

To make the internet more user-friendly, developers use ways to store information about you temporarily or permanently. This helps with:

  • Logging you in
  • Saving shopping cart contents
  • Remembering site settings (like dark mode)
  • Tracking visitors for analytics or ads

A cookie is a small text file that a website asks your browser to store. It usually contains a key-value pair, like:

user_id=12345

Whenever you visit the site again, your browser sends the cookie back so the server can recognize you.

  • Set by the server (or JavaScript on the site)
  • Stored in your browser
  • Sent automatically with each request to the same domain
  • Keeping you logged in
  • Tracking your activity across pages
  • Saving preferences (like language or theme)
  • Session cookies disappear when you close your browser
  • Persistent cookies stay until a set expiration date

Some cookies are marked as:

  • Secure – only sent over HTTPS
  • HttpOnly – not accessible via JavaScript (helps prevent attacks)
  • SameSite – restricts when cookies are sent across different sites

A session is a way for a website to store information about you on the server instead of in your browser.

  • When you log in, the server creates a session with your info
  • The server sends you a session ID, usually stored in a cookie
  • Your browser sends that ID back on every request
  • The server uses the ID to find your session and know who you are
  • User authentication (logged-in status)
  • Temporary form data
  • Shopping carts on dynamic websites
  • Cookies store data in the browser
  • Sessions store data on the server (only the session ID is in the browser)

Local storage is a way for websites to save larger amounts of data in your browser, and it doesn’t get sent back to the server automatically.

  • JavaScript on the website can store key-value pairs
  • The data stays even if you close the tab or browser (until you or the site clears it)
localStorage.setItem("theme", "dark");
  • Saving theme preferences
  • Caching small amounts of data for performance
  • Remembering settings on single-page apps
  • Local storage is domain-specific
  • Can store about 5–10MB of data (much more than cookies)
  • Not automatically encrypted—avoid storing sensitive info
FeatureCookiesSessionsLocal Storage
Stored InBrowserServerBrowser
Accessible ByServer & JavaScriptServer onlyJavaScript only
ExpiresCan expire or be persistentUsually when browser closesPersistent until deleted
Sent With RequestsYes (automatically)Only session ID in cookieNo
Use CasesLogin, tracking, settingsAuth, temporary stateSettings, caching

Knowing how the web remembers you helps explain:

  • Why you stay logged in
  • How ads track your behavior
  • Why clearing cookies logs you out of sites
  • How developers build more responsive and personalized websites

If you’re learning about how the internet works, this topic will become important is you progress in your Pentesting career.

  • Cookies store small bits of info in your browser and get sent to the server
  • Sessions store data on the server and use a cookie to identify you
  • Local storage keeps data in your browser for use by front-end code

These tools let websites behave more like apps—and make your experience smoother and more personalized.

Scroll to Top