How can PHP prevent data from being saved multiple times when the browser's refresh button is clicked?

When the browser's refresh button is clicked, it resubmits the form data, causing it to be saved multiple times. To prevent this, we can use a technique called Post/Redirect/Get (PRG) pattern. After processing the form data, we redirect the user to a different page using the header() function to prevent the form data from being resubmitted when the refresh button is clicked.

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