What are the advantages and disadvantages of using sessions to store form data in PHP?
When storing form data in PHP, using sessions can be advantageous as it allows the data to persist across multiple pages without the need to constantly pass it through form submissions. However, sessions can also introduce security risks if not properly handled, such as session hijacking or session fixation attacks.
// Start session
session_start();
// Store form data in session variables
$_SESSION['username'] = $_POST['username'];
$_SESSION['email'] = $_POST['email'];
// Retrieve form data from session variables
$username = $_SESSION['username'];
$email = $_SESSION['email'];