• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Countdown Timer on every navigated webpages

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I would like to have a countdown timer (example: 60min, I use MS Visual Studio C# or javascript) for my websites so that the timer can countdown as I navigated from one webpage to another webpage until I click on the Logout button or the timer will auto logout the user once the 60min countdown is reached. I was not able to get the required timer codes from Google search because either the timer cannot be started or activate upon successfully login or  the timer will always restarted/reset by itself on the redirected webpage which mean it is not able to continue the countdown process from one webpage to another webpage. Thanks.
 
Bartender
Posts: 15737
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

You should store the time the user last logged in in their session. You can calculate the amount of time they've been logged in by subtracting the current time from the login time.

When the remaining time is zero and the user GET requests a page that requires authentication, you forward them to a page notifying them their session has timed out and that they need to log in again. Don't do this for requests other than GET, because a user might want to save changes they've made before the time ran out.

You can also introduce a live timer in JavaScript on the web page that counts down from the remaining time to zero, but you shouldn't let it automatically redirect when it reaches zero, because once again, the user might lose information they've typed into forms etc.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic