How can PHP be used to redirect users to different pages based on form submission?

To redirect users to different pages based on form submission in PHP, you can use the header() function to send a raw HTTP header to the browser. You can use this function to specify the location where the user should be redirected after the form is submitted.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Check which form was submitted
    if ($_POST['form1']) {
        header("Location: page1.php");
        exit();
    } elseif ($_POST['form2']) {
        header("Location: page2.php");
        exit();
    } else {
        header("Location: default_page.php");
        exit();
    }
}
?>