Jump to content

GerardWay

New Members
  • Posts

    1
  • Joined

  • Last visited

GerardWay's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have a button which I want a specific output for after being clicked once and a specific output after being clicked twice. How can I do this? I tried to use cookies. <!-- This is in index.php --> <a href="action.php"><button class="btn">Click</button></a> I want it to set the cookie 'clicked_once' after it has been clicked once and then go back to the button page after three seconds: <?php // Check if the 'clicked once' cookie has already been set if(!isset($_COOKIE['clicked_once'])) { // If not, set it setcookie('clicked_once', getIP()); ?> <div class="notice"> <p>You have clicked the button once. <a href="javascript:history.go(-1)">Go back to click it again</a> </p> </div> <?php } ?> Then, once the user has clicked the button again, I want to set the *'used_twice'* cookie (which expires after an hour) and give them the result: <?php // Check if the 'clicked once' cookie is set... // ... and if the 'clicked twice' one hasn't // If so, unset the 'clicked once' cookie and set the 'clicked twice' one // And then give them the result if(isset($_COOKIE['clicked_once']) && !isset($_COOKIE['used_twice'])) { unset($_COOKIE['clicked_once']); setcookie('clicked_twice', getIP(), time()+3600); ?> <div class="notice"><p>Success!</p></div> <?php } ?> After that and they try to click the button again I want it to give an error message: // If the button has been clicked twice then provide no result <?php if(isset($_COOKIE['clicked_twice'])) { ?> <div class="notice"><p>You can only do this once every hour. Please try again later.</p></div> <?php } ?> This is not working though. Once you click the button on index.php, here is the output: Warning: Cannot modify header information - headers already sent by (output started at getMem.php:65) getMem.php on line 69 You have clicked the button once. Go back to click it again. When you click the button again, you get the same output. Here is the output I want from clicking the button once: You have clicked the button once. Please allow the page to refresh and click it again. Here is the output I want from clicking the button twice: Here is your code: {code pulled from list} I also checked my browser and no cookies had been set.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.