Thursday, April 21, 2011

Page Session Countdown Timer

I wrote a PHP code that kills the session after 5 minuets from creation.

I would like to display a timer in the corner of the page that shows the user how many minutes:seconds till the session times out. Are there any good examples out there?

From stackoverflow
  • Something like this?

    There you have a simple example showing how to use it:

    var newYear = new Date(); 
    newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1); 
    $('#defaultCountdown').countdown({until: newYear}); 

    So now what we need is a UNIX timestamp (time when session will end). Then we can modify it like this:

    var endOfSession = new Date(youtitmestamp * 1000); // timestamp is in seconds and we need miliseconds
    $('#defaultCountdown').countdown({until: endOfSession}); 

    Hope it helped!

    Mcgo : yes, how can I integrate it with the session time stored in server?
    Balon : If you could create a code which kills the session after 5 minutes from creationg, you could easily calculate time left before end of session.
    Mcgo : I can calculate that, but I don't know how to show that to user in a dynamic way, like your example. please help me, I am new to javascript, but I know PHP well enough.
    Balon : I added an example to my answer ;)


Post a Comment