What potential pitfalls should be considered when assigning values from POST to SESSION in PHP?

When assigning values from POST to SESSION in PHP, it's important to validate and sanitize the input data to prevent security vulnerabilities such as injection attacks. Additionally, be cautious of storing sensitive information in the session as it can be accessed by other scripts on the server. It's also crucial to unset the session variables once they are no longer needed to avoid potential data leakage.

// Validate and sanitize input data from POST
$validated_data = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);

// Assign validated data to session
$_SESSION['data'] = $validated_data;

// Unset session variables when no longer needed
unset($_SESSION['data']);