You can try doing it this way:
if (! $_SESSION['dh_acesso'])
{
$_SESSION['dh_acesso'] = new DateTime();
$permite = TRUE;
}
else
{
$dh_atual = new DateTime();
if ($dh_atual->diff($_SESSION['dh_acesso'])->i > 3)
{
$permite = TRUE; // Passou 3 min., então pode permitir...
unset($_SESSION['dh_acesso']); // Esvazia a sessão para um novo ciclo
}
else
{
$permite = FALSE;
}
}
if ($permite)
{
// Chama a função aqui...
}
On the first attempt, the $_SESSION['dh_acesso']
which will store the date and time of access and the flag $permite
will be defined as TRUE
. Then your function can be executed.
On the second attempt, the else
shall be carried out, that is, the validation of the time $_SESSION['dh_acesso']
. Therefore, if the 3 minutes have been exceeded, your function can be executed and the session will be emptied to start a new cycle. Otherwise, the execution will be prevented.
Remember to give the session_start()
and configure the date_default_timezone_set()
correctly.
It’s an idea. :)
Global or per user? can record in the session or in the database, and make a validation before making the call, so I know the only way is this.
– arllondias
Global, has no database.
– LucasRodz
It depends on what its function does, if it is a loop that rotates infinitely it may be possible to implement, otherwise it will be difficult.
– Guilherme Nascimento
Negative, command is executed, then it shows the information, it will only show again when command is executed again
– LucasRodz
You can’t assume anything if we don’t know how the code works, you’re just stating because you know what you did, what I said is based on what you can understand, and there’s a detail, PHP is not asynchronous, so some kind of operation will have to occur, or recursion or loop to get, or you just want a check, but the way this one can not tell what is the solution to your case.
– Guilherme Nascimento