Is it generally unsafe to directly write $_POST values into the $_SESSION array without filtering or validation?
It is generally unsafe to directly write $_POST values into the $_SESSION array without filtering or validation because it opens up the possibility of security vulnerabilities such as injection attacks. To solve this issue, you should always sanitize and validate user input before storing it in the session to prevent potential exploits.
// Sanitize and validate the $_POST value before storing it in the $_SESSION array
if(isset($_POST['input'])){
$filteredInput = filter_var($_POST['input'], FILTER_SANITIZE_STRING);
$_SESSION['input'] = $filteredInput;
}