Session Introduction

A special object created by the server to store user state.
The primary function of a session is to record user state on the server side. A session represents another mechanism for recording server-client session state.
Sessions are used to identify specific client information, which is stored in a file on the server.
Typically, clients access the server using cookies; they can retrieve server-recorded information about the client by querying the session ID contained within the cookie.

How Session Works

After a client logs in successfully, the server creates a corresponding session. Once the session is created, its ID is sent to the client, which then stores it in the browser. Consequently, every time the client accesses the server, it includes the session ID. Upon receiving the session ID, the server locates the corresponding session in memory, enabling normal operation.

Typical Use Cases

Shopping carts. Due to the stateless nature of the HTTP protocol, the system cannot determine which user performed an action. Sessions resolve this issue by maintaining user-specific state.