Lesson content
Read, practise, then check your understanding
Cookies live on the client; sessions usually store state server-side and send a random identifier. Configure cookie behavior before session_start.
Practical example
<?php
session_set_cookie_params(['secure' => true, 'httponly' => true, 'samesite' => 'Lax']);
session_start();
session_regenerate_id(true);
$_SESSION['user_id'] = $userId;
Rotate IDs after authentication/privilege changes, enforce idle and absolute expiry, and prevent fixation. Secure requires HTTPS, HttpOnly blocks script access, and SameSite limits cross-site inclusion but does not replace CSRF protection. Store minimal state.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.