How can PHP sessions be used to prevent users from submitting a form multiple times?

To prevent users from submitting a form multiple times, you can use PHP sessions to track whether the form has already been submitted by a particular user. When the form is submitted, you can set a session variable to indicate that the form has been processed. Before processing the form, you can check this session variable to ensure that the form is not submitted multiple times.

<?php
session_start();

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    if (!isset($_SESSION['form_submitted'])) {
        // Process the form
        $_SESSION['form_submitted'] = true;
    } else {
        echo "Form has already been submitted.";
    }
}
?>