Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda