What is the best way to handle form redirection in PHP based on user input?

When handling form redirection in PHP based on user input, you can use conditional statements to check the input and redirect the user accordingly. You can use header() function in PHP to redirect the user to a different page based on the input provided by the user.

<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
    // Process the form data
    $userInput = $_POST['input'];

    // Check user input and redirect accordingly
    if($userInput == 'option1'){
        header("Location: page1.php");
        exit();
    } elseif($userInput == 'option2'){
        header("Location: page2.php");
        exit();
    } else {
        header("Location: error.php");
        exit();
    }
}
?>