How can you prevent a PHP script from adding the same data multiple times when the user clicks on the reload button in the browser?

To prevent a PHP script from adding the same data multiple times when the user clicks on the reload button in the browser, you can use a POST-Redirect-GET pattern. After processing the form data, you can redirect the user to another page using the header() function to prevent form resubmission on page refresh.

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