user1001176
user1001176

Reputation: 1163

saving value of jquery countdown timer in php session

I am using the following Jquery flip timer . I am using it as the countdown verison . My code is

var clock;

$(document).ready(function() {
    var clock;

    clock = $('.clock').FlipClock(<?php echo $total_time;  ?>, {
        clockFace: 'MinuteCounter',
        countdown: true,
        callbacks: {
            stop: function() {
                $('.message').html('The clock has stopped!')
            }
        }
    });

});

I am getting the time dynamic here in minutes . The problem is whenever i refresh the page the counter resets . How to save the counter's value so that it can resume from where it was before the page refresh ?

Upvotes: 0

Views: 1575

Answers (2)

user1001176
user1001176

Reputation: 1163

I made this code and it works exactly the way i wanted thank you @Ezekiel for your help.

        var clock;

        $(document).ready(function() {
            var clock;

            clock = $('.clock').FlipClock(<?php echo $final_time;  ?>, {
                clockFace: 'MinuteCounter',
                countdown: true,
                callbacks: {
                    start: function() {
                        setInterval(function(){
                        var time  = clock.getTime();
                        //alert(time);
                            imStillAlive(time);
                        }, 2000);
                    },              
                    stop: function() {
                        $('.message').html('The clock has stopped!')
                    }
                }
            });

        });


function imStillAlive(time) { 

     $.post('modules/view_test/ajax.php?timer='+time,
     function(data){
        //alert("updated");
     });//post
}

Upvotes: 0

Ezekiel
Ezekiel

Reputation: 2515

What Barmar said is correct, you should use the localStorage[] variable. However, if for whatever reason you need to save it to $_SESSION, you should use ajax. Like so:

$.get('savetimer.php?timer=' + timer);

Like all client code, this can be manipulated by the user.

Upvotes: 2

Related Questions