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'];
}
?>
Keywords
Related Questions
- How can PHP developers optimize memory usage when working with large arrays of data fetched from a database in their applications?
- How can PHP developers avoid pitfalls when using print_r() or var_dump() for debugging and displaying array data in HTML?
- What potential issues can arise when using PHP to filter and display data based on user input such as month selection?