How can PHP prevent a form from being submitted multiple times by clicking the submit button rapidly?

To prevent a form from being submitted multiple times by clicking the submit button rapidly, you can use JavaScript to disable the submit button after it has been clicked once. This will prevent users from submitting the form multiple times before the server-side processing is completed.

<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Process form data
    
    // Disable the submit button
    echo '<script>document.getElementById("submitBtn").disabled = true;</script>';
}
?>