🐘 PHP
Beginner
What are sessions in PHP?
Answer
A session is a mechanism to store user-specific information on the server across multiple HTTP requests. Because HTTP is stateless, sessions provide continuity between page loads. Start a session with session_start() (must be called before any output). Store data: $_SESSION["user"] = "Alice";. Retrieve data on the next page: echo $_SESSION["user"];. PHP generates a unique session ID (usually stored in a cookie named PHPSESSID) that links the browser to the server-side session data. Destroy a session: session_destroy(). Sessions are more secure than cookies for storing sensitive data (like user IDs after login) because the data lives on the server, not in the browser.