What are the advantages and disadvantages of storing user IDs in session variables for profile management in PHP?

Storing user IDs in session variables for profile management in PHP can provide easy access to user information throughout a user's session. However, it may pose security risks if the session data is not properly secured or validated. It is important to ensure that sensitive user information is not exposed or manipulated by unauthorized users.

<?php
session_start();

// Set user ID in session variable
$_SESSION['user_id'] = $user_id;

// Retrieve user ID from session variable
$user_id = $_SESSION['user_id'];
?>