Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6238771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:16:27+00:00 2026-05-24T11:16:27+00:00

I would like to create a countdown clock that when you show up on

  • 0

I would like to create a countdown clock that when you show up on the page it starts to countdown from a pre-defined number, say 8 hours. If you leave the page, say after 2 hours, I would like it to stop counting down. If you return to the page I want it to resume counting down, now with only 6 hours left.

Is this possible using javascript client side, and php server side?

If I wanted to create multiple user generated countdowns can I use mySQL to store the different variables?

Obviously I have a lot to work out here, I don’t want someone to write me the whole code. I am looking for a starting point, maybe some tutorials or advice on which way to start perusing. I am very much a novice at js, php, mysql but can work with them.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:16:27+00:00Added an answer on May 24, 2026 at 11:16 am

    Here’s a solution that uses a countdown plugin for jQuery. Download the jQuery Countdown plugin, and place jquery.countdown.css and jquery.countdown.min.js in the same folder as your file (or elsewhere, and adjust the paths in the code below). In the head section of your document include this:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="jquery.countdown.min.js"></script>
    <style type="text/css">@import "jquery.countdown.css";</style>
    

    Somewhere in the PHP code, before anything is outputted, run this to set when the time will be:

    if (!isset($_COOKIES['endtime'])) {
        $endtime = time() + 28800000;
        setcookie('endtime', $endtime);
    } else {
        $endtime = $_COOKIE['endtime'];
    }
    

    Then, where you want the timestamp to appear, output this HTML:

    <span class="countdown hasCountdown" id="myCountdown"></span>
    

    And somewhere after it, output this JavaScript:

    var targetDate = new Date(<?php echo ($endtime ); ?>); 
    $('#myCountdown').countdown({until: targetDate});
    

    EDIT: Alright, here are some improvement on my previous answer to include pausing when the user leaves the page. I’m also switching the post over to community wiki so anyone is welcome to edit and improve it.

    In order to track when the user was last on the page, you need to keep a cookie that you update every 5 seconds or so with the current time. Here’s a bit of JavaScript that does just that:

    function setCookie(c_name, value, exdays)
    {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + exdays);
        var c_value = escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
        document.cookie = c_name + "=" + c_value;
    }
    
    function updateCookie()
    {
        var curTime = new Date();
        setCookie('lastvisit', curTime.getTime(), 30);
        setTimeout("updateCookie()", 5000);
    }
    

    You need to run updateCookie() once and then it will keep running every five seconds. To have it run for the first time as soon as the page has finished on loading, add an onLoad to your body tag, like this:

    <body onLoad="updateCookie()">
    

    Your PHP code will then look like this instead of the one above:

    if (!isset($_COOKIES['lastvisit']) || !isset($_COOKIES['endtime'])) {
        $endtime = (time()*1000) + 28800000;
        setcookie('endtime', $endtime, time() + 2592000);
    } else {
        $prevendtime = $_COOKIE['endtime'];
        $lastvisit = $_COOKIE['lastvisit'];
        $timeleft = $prevendtime - $lastvisit;
        $endtime = (time()*1000) + $timeleft
    }
    

    All the cookies are set to expire after 30 days, so if your user stays away for more than 30 days they will reset.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like create a custom DataRow that will have -let's say- a propery
I would like create my own collection that has all the attributes of python
I would like create a web service in ASP.Net 2.0 that will supports JSON.
I would like to create a stored procedure in MySQL that took a list
I would like to create events for certain resources that are used across various
I would like create URL rewrite rule that will set default document for my
I would like create a database using value from a variable. Here my script
would like to create a function that generates graphs using ggplot. For the sake
I would like create alarm clock at windows phone 7 mango , for this
Good afternoon, I would like create a application that can can create folders and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.