What are some best practices for handling user input data preservation in PHP applications, especially when navigating away from a page?

When handling user input data preservation in PHP applications, especially when navigating away from a page, it is important to store the input data in a session variable before redirecting or displaying a new page. This ensures that the user's input is not lost and can be retrieved when needed.

// Start the session
session_start();

// Store user input data in a session variable
$_SESSION['user_input'] = $_POST['input_data'];

// Redirect to a new page
header("Location: new_page.php");
exit;