A hotel room key card
Day 45 of 149
๐ Full deep-dive with code examples
The Hotel Key
At a hotel:
- You check in at the front desk
- They give you a key card
- Key card opens YOUR room, not others
- When you check out, key stops working
Sessions work the same way!
How It Works
- You log in to a website
- Server creates a "session" for you
- Gives your browser a session ID (like a key card)
- Session ID unlocks YOUR data on the server
Login โ Server creates Session #12345
โ Browser stores ID: "12345"
Every request: "I'm session 12345"
Server: "Ah yes, that's Alex! Show Alex's dashboard."
Sessions vs Cookies
Cookie: Data stored in YOUR browser
Session: Data stored on the SERVER, you just have the ID
Sessions can reduce exposure because sensitive data typically stays on the server (the browser usually only keeps an ID).
When Sessions End
- You log out (check out)
- You close the browser
- Too much time passes (timeout)
In One Sentence
Sessions let servers remember who you are by giving your browser an ID that links to your data on the server.
๐ Enjoying these? Follow for daily ELI5 explanations!
Making complex tech concepts simple, one day at a time.
Top comments (0)