How can PHP utilize the Post-Redirect-Get pattern to prevent duplicate form submissions?

When a form is submitted in PHP, it can lead to duplicate form submissions if the user refreshes the page after submitting the form. To prevent this, we can utilize the Post-Redirect-Get pattern. This pattern involves processing the form submission, redirecting to a different page using the header() function, and then displaying the result on that page. This way, if the user refreshes the page, they are not resubmitting the form data.

// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data
    
    // Redirect to a different page
    header("Location: result.php");
    exit();
}

// Display the form
// This can be in the same file or a different file