What are the potential security risks associated with storing user IDs in sessions in PHP?
Storing user IDs in sessions in PHP can lead to security risks if the session data is not properly secured. An attacker could potentially hijack a session and gain unauthorized access to another user's account by manipulating the session data. To mitigate this risk, it is recommended to encrypt sensitive data stored in sessions and validate the session data before using it.
// Encrypt and store user ID in session
$_SESSION['user_id'] = encrypt($user_id);
// Decrypt user ID from session
$user_id = decrypt($_SESSION['user_id']);