Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

214
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!