How to send only one form once every 5 minutes

2

Well, I wanted to know, how could I make the person submit form only within 5 minutes.

<?php
    $nome  = $_POST["nome"];
$locutor = $_POST["locutor"];
$texto = $_POST["texto"];
$coment = "INSERT INTO 'pedidos' ( 'nome' , 'locutor' , 'texto', 'data' , 'id', 'num' ) VALUES ('$nome', '$locutor', '$texto', now(), '', '')";

mysql_query($coment);
?>
    
asked by anonymous 02.08.2015 / 22:51

1 answer

1

You can use session to save session data of a given user.

A simple example might look like this:

session_start();
$date = new DateTime();
$now = $date->getTimestamp();
if (!isset($_SESSION['ultimo_timestamp'])) {
  $_SESSION['ultimo_timestamp'] = $now;
} else {
  if($now - $_SESSION['ultimo_timestamp'] < 5 * 60) die('Ainda não passaram 5 minutos...');
  else $_SESSION['ultimo_timestamp'] = $now;
}

In this way, you keep the object $_SESSION the timestamp (in seconds) since the last submission of the form and give a message if it has not yet been 5 minutes.

    
03.08.2015 / 00:06