0

I know how to check cookie by php but don't know how to configure it to show time countdown

below is the code that I use to detect cookie

    <?php
     if (isset($_COOKIE["user"]))
    ?>

all I want is if cookie exists then show a countdown for 5 minutes like the below image

Image countdown

Krish R
  • 21,556
  • 6
  • 47
  • 57

1 Answers1

1

Remember that PhP is a server side language, using the server/client model, if you want to display something to the user, you need to pass data to client, then display that data using a client side language.

For this, I recommend using a javascript countdown.

An example of passing the information between client and server would be like so:

<?php
if (isset($_COOKIE["user"]))
{
    $setTimer = "true";
}
?>

And your javascript..

var setTimer = "<?php Print($setTimer); ?>";
if(setTimer)
{
DisplayATimer
}

If you're looking for a javascript timer, and are unsure how to make one, I'm sure there's a few you can grab if you google around. It's also worth noting that javascript has full access to cookies, as they're stored locally. So unless you need to do something with your PhP, it may be better to just check for the cookie within javascript.

How do I set/unset cookie with jQuery? This post is helpful in that regard.

Community
  • 1
  • 1
  • http://www.gieson.com/Library/projects/utilities/countdown/ Here's a countdown timer I found with some quick googling. It's pretty straight forward to use, so I leave implementing it on your webpage up to you. Good luck! Be sure to read the readme and pay close attention to the example given. –  Nov 15 '13 at 05:32
  • this is the javascript var myCountdown2 = new Countdown({ time: 300, width:200, height:80, rangeHi:"minute" // – user2982013 Nov 15 '13 at 05:46
  • var myCountdown2; if(setTimer) { myCountdown2 = new Countdown({ time: 300, width:200, height:80, rangeHi:"minute" } Just put it in an if statement, if it's true, it'll create the countdown. If it isn't it won't. It seems like you could benefit from some basic javascript tutorials. They'll help you in the long run. –  Nov 15 '13 at 05:48