Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
create button can click only one time in 24 hours

i'm trying to create button can click only one time in 24 hours , Even if user left the page and came back, he finds it unavailable until the 24h end , I don't mind any possible way (java script , database , jquery , php). thank you all guys

i have this code html:

  <form action="#" method="POST">

<div class="card1" id="card1">
            <h3>book 1</h3>
         <button id="roll1""name="roll1"><a href="bbb.php">read now</a></button>
    </div>
<div class="card2" id="card2">
        <h3>book 2</h3>            
         <button id="roll2" "name="roll2"> <a href="ccc.php">read now</a></button>
    </div>
<div class="card3" id="card3">
        <h3 >book 3</h3>
         <botton id="roll3" "name="roll3""> <a href="aaa.php">read now</a></button>
    </div>
</form>

I tried to do that but when user refresh the button back Enabled :

<?php 

if(isset($_POST['roll'])) {

echo 'you can not click , try again later'; 
}

?>

<form action="aaa.php" method="POST">
    <button type="submit" name="roll" <?php echo isset($_POST["roll"]) ? 
     "disabled" : "";?>>read now </button> 
</form>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can try this with session. If session is persisted to a DB, It will be better, because the user can delete the session on the browser.

On your index.php file (where your form is), you can have this :

<?php
session_start();
?>

<form action="aaa.php" method="POST">
    <button type="submit" name="roll" value="roll"
        <?php
        echo isset($_SESSION["lock_timestamp_24h"]) &&
         date('m/d/Y H:i:s', time())  <= date('m/d/Y H:i:s', $_SESSION["lock_timestamp_24h"]) ? 'disabled' : ''
        ?>
    >read now
    </button>
</form>

As I see in your question you post on aaa.php file. So on this file, you could do this :

<?php

session_start();

if (isset($_POST['roll'])) {
    if( !isset($_SESSION["lock_timestamp_24h"]) ) {
        $_SESSION["lock_timestamp_24h"] = strtotime("+ 1 day", (new DateTime())->getTimestamp());
    }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda