What is the recommended approach to handle form submission in PHP to avoid the browser prompting to resubmit data?

When a form is submitted in PHP and the user refreshes the page, the browser may prompt to resubmit the data. To avoid this, you can use the POST/Redirect/GET pattern. After processing the form data, redirect the user to a different page using the header() function to prevent the resubmission prompt.

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Process form data here

    // Redirect to a different page to avoid resubmission prompt
    header("Location: success.php");
    exit;
}
?>