How can sessions be used to implement a 30-second delay for sending a message in PHP form submissions?

To implement a 30-second delay for sending a message in PHP form submissions, you can use sessions to store a timestamp when the form is submitted. When the form is submitted again, you can compare the current timestamp with the stored timestamp to check if 30 seconds have passed before sending the message.

session_start();

if(isset($_SESSION['last_submit_time']) && time() - $_SESSION['last_submit_time'] < 30){
    echo "Please wait 30 seconds before sending another message.";
} else {
    // Process the form submission and send the message

    // Store the current timestamp in the session
    $_SESSION['last_submit_time'] = time();

    echo "Message sent successfully!";
}