Loading Depth Study
Preparing your workspace
Authentication verifies a user's identity, while authorization determines what that authenticated user is allowed to access.
Traditional PHP applications commonly use server-side sessions to remember authenticated users between requests. After a successful login, the application can store the user identity in the session and require authentication on protected pages. Passwords should never be stored as plain text; password_hash and password_verify should be used for password storage and checking. Authorization then checks roles or permissions before allowing sensitive actions.
A learning platform can let students access their dashboard while restricting course management and user administration to authorized staff.
<?php
session_start();
if (!isset($_SESSION['user_id'])) {
http_response_code(401);
exit('Authentication required');
}
echo 'User is authenticated';The page allows access only when an authenticated user ID exists in the session.