
A cookie is a small piece of data stored in the user’s browser by a website to remember information about the user.
A cookie is a small piece of data stored in the user’s browser by a website to remember information about the user.
A session is a server-side mechanism used to store user data temporarily on the server during a user’s interaction with a website.
Cookies → Stored in Browser (Client-side)
Sessions → Stored on Server (Server-side)
Browser → Request → Server
Server → Sends Cookie → Browser stores it
Next request → Cookie sent back automatically
setcookie("user", "Ali", time() + 3600);
User → Login → Server creates Session ID
Server stores data → Browser stores Session ID only
session_start();
$_SESSION["user"] = "Ali";
| Feature | Cookies 🍪 | Sessions 🔐 |
|---|---|---|
| Storage | Browser | Server |
| Security | Less secure | More secure |
| Size | Small (4KB) | Large |
| Expiry | Can be set | Ends on logout/time |
| Speed | Faster | Slightly slower |
| Control | Client-side | Server-side |
Cookies:
User ↔ Browser ↔ Server
Sessions:
User ↔ Browser (Session ID) ↔ Server (Stores Data)
✔ Cookies store user preferences ✔ Sessions store sensitive data ✔ Cookies are less secure ✔ Sessions are more secure ✔ Both are used for state management in HTTP (stateless protocol)
👉 HTTP is stateless, meaning it does not remember users. ✔ Cookies and Sessions solve this problem.
👉 Both are essential for login systems, user tracking, and personalization in web applications.
Open this section to view and download past papers
Click on Show Past Papers to load available exam papers.