What is the best practice for implementing a form that redirects to a specific URL based on user input in PHP?

When implementing a form that redirects to a specific URL based on user input in PHP, you can achieve this by using a conditional statement to check the user input and then use the header() function to redirect to the desired URL.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $user_input = $_POST['user_input'];

    if ($user_input == 'option1') {
        header("Location: https://example.com/page1");
        exit();
    } elseif ($user_input == 'option2') {
        header("Location: https://example.com/page2");
        exit();
    } else {
        header("Location: https://example.com/default_page");
        exit();
    }
}
?>