What are the recommended methods for handling form submissions and URL redirection in PHP?

Handling form submissions and URL redirection in PHP can be done by checking if the form has been submitted using the POST method, processing the form data, and then redirecting the user to a new page using the header() function with the Location parameter set to the desired URL.

<?php
// Check if the form has been submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process the form data
    $username = $_POST["username"];
    $password = $_POST["password"];
    
    // Redirect the user to a new page
    header("Location: new_page.php");
    exit();
}
?>