Course contentsShow
← Security
Lesson 703 of 3,05215. Web Security - Authentication and SessionsFree lesson

What is a Session and Why Web Apps Need Them

Understanding HTTP statelessness and how sessions enable server-side state tracking across multiple requests.

What is a Session and Why Web Apps Need Them

You'll learn: Why HTTP has no built-in memory and how sessions solve this fundamental problem.


The Stateless Problem

HTTP is stateless by design. This means each request you make to a web server is completely independent—the server doesn't remember who you are between requests. It's like walking into a store where the clerk forgets you exist every time you blink.

Imagine logging into a banking website. Without sessions, you'd need to send your username and password with every single request—viewing your balance, transferring money, clicking any link. That would be a security nightmare and terrible user experience.

Enter the Session

A session is a server-side mechanism for maintaining state across multiple HTTP requests from the same user. Here's how it works:

  1. When you successfully authenticate (log in), the server creates a session and stores your authentication status and user data server-side
  2. The server generates a unique session identifier (session ID) and sends it to your browser
  3. Your browser includes this session ID with every subsequent request (usually via a cookie)
  4. The server reads the session ID, looks up your session data, and "remembers" you're logged in

Why Sessions Matter for Security

Sessions enable secure authentication without repeatedly transmitting credentials. Instead of sending your password with every request, you send an opaque session ID. If that ID is stolen, you can invalidate the session—something impossible with passwords alone.

Sessions also enable critical security features like:

  • Activity timeouts (auto-logout after inactivity)
  • Access control (tracking user permissions)
  • Audit trails (associating actions with authenticated users)

Key Takeaway: Sessions bridge HTTP's stateless nature by letting servers remember authenticated users across requests, enabling secure, persistent login experiences without repeatedly transmitting credentials.