How can the issue of multiple form submissions be prevented when users click the back button in a browser?

When users click the back button in a browser, they may inadvertently resubmit a form multiple times, leading to duplicate entries in the database or unintended actions. To prevent this issue, we can use a technique called Post/Redirect/Get (PRG), where after processing the form submission, we redirect the user to a different page using the header() function in PHP. This way, if the user clicks the back button, they will be taken to the redirected page instead of resubmitting the form.

// Process form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Validate and save form data

    // Redirect to a different page to prevent resubmission
    header("Location: success.php");
    exit();
}