How can a form in PHP be set up to have multiple possible output pages that can all accept variables?

When setting up a form in PHP that can lead to multiple possible output pages, you can use a conditional statement to determine which page to redirect to based on certain criteria. To ensure that all output pages can accept variables, you can pass the variables through the URL parameters or by using sessions. This way, each output page can access the necessary data to display the information correctly.

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST'){
    // Process form data
    $variable1 = $_POST['variable1'];
    $variable2 = $_POST['variable2'];
    
    // Determine which page to redirect to based on criteria
    if($variable1 == 'criteria1'){
        header('Location: page1.php?variable1=' . $variable1 . '&variable2=' . $variable2);
    } elseif($variable2 == 'criteria2'){
        header('Location: page2.php?variable1=' . $variable1 . '&variable2=' . $variable2);
    } else {
        header('Location: default_page.php');
    }
    exit;
}
?>