What are the potential pitfalls of allowing users to refresh a page and resubmit form data in PHP?

Allowing users to refresh a page and resubmit form data in PHP can lead to duplicate form submissions and unintended actions being performed multiple times. To prevent this, you can use a technique called Post/Redirect/Get (PRG) pattern. After processing the form data, redirect the user to a different page using a HTTP redirect header. This way, if the user refreshes the page, the form data will not be resubmitted.

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