How can the PHP header function be used effectively for redirecting to a new page after form submission?

When a form is submitted in PHP, you can use the header function to redirect the user to a new page after processing the form data. This is commonly done to avoid form resubmission when the user refreshes the page. To redirect to a new page after form submission, simply use the header function with the location header set to the URL of the new page.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data here
    
    // Redirect to a new page after form submission
    header("Location: newpage.php");
    exit;
}
?>