How can form data from $_POST be stored in a session variable in PHP?

To store form data from $_POST in a session variable in PHP, you can simply assign the $_POST values to the session variable. This allows you to access the form data across different pages during the user's session.

<?php
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $_SESSION['username'] = $_POST['username'];
    $_SESSION['email'] = $_POST['email'];
}
?>