How can a PHP script prevent data from being resubmitted to the database when a page is reloaded?

When a page is reloaded, a PHP script can prevent data from being resubmitted to the database by using a technique called "post/redirect/get." This involves processing the form submission, storing the data in the database, and then redirecting the user to a different page using the header function. This way, if the user refreshes the page, the form data will not be resubmitted.

// Process form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Store data in the database
    // Redirect to a different page to prevent form resubmission
    header("Location: success.php");
    exit;
}