tags:

views:

37

answers:

1

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?

A: 

Something like this? http://keith-wood.name/countdown.html

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!

Balon
yes, how can I integrate it with the session time stored in server?
Mcgo
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.
Balon
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.
Mcgo
I added an example to my answer ;)
Balon