Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remaining time before the session timeout expires 3

Status
Not open for further replies.

REK2

Programmer
Apr 30, 2003
22
CA
Hi all,
I would like to retrieve the remaining time of the user session. Is this possible?

Example, if am idle for 20 minutes then the session.timout fire's up. I only need to be able to know in how much time the session will effectivly timout.


Thanks alot
 
I assume you don't want an ASP to report this, as every page would report the full time remaining, as every page would reset to timeout countdown.

Hence, if you DO want this, you may as well just return the Session duration (Session.Timeout).



codestorm
Fire bad. Tree pretty. - Buffy
Kludges are like lies.
You're not a complete programmer unless you know how to guess.
I hope I never consider myself an 'expert'.
<insert witticism here>
 
I use javascript to track the remaining time in the session (client-side) since, as codestorm says, every server hit restarts the clock.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Thanks for your replies guy's.
Yep I was aware of this, and maybe the second solution would be my best bet. The only thing I want to do is put in the status window, the remaining time of the user's session before he get's timout. The users in my case have different timout values that I set in the user's table and when they log in I set the session.timout to be equal to the user timout settings.

So I only want to show him the remaining time of his session via the status bar. Of course, when he will be working, this time will always reset to the initial value, but this will be usefull when example he had left for what ever reason and come back to his screen.

Is this still possible with javascript client-side? if so.. is it possible to point me out to a starting snippet or something as I really have no clue at the moment.

Thanks alot
 
<script>
var timeLeft = <%=session.timeout%> * 60
function startTimer(){
timeLeft --
if (timeLeft < 0) {
closeWin(&quot;&quot;)
}
minsLeft = Math.floor(timeLeft / 60)
secsLeft = timeLeft - (minsLeft * 60)
if (secsLeft < 10){
secsLeft = &quot;0&quot; + secsLeft
}
window.status = minsLeft + &quot;:&quot; + secsLeft
timerID = setTimeout(&quot;startTimer()&quot;,1000)
}
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Sorry - I forgot to mention this line

<body onLoad=&quot;startTimer()&quot;>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
@mwolf00, Thanks a bunch. This is exactly what I wanted.

Really appreciate your input.

Thanks again.

Greetings
 
I'm glad it works for you, I just noticed that then the time runs out, it calls closeWin(). You may want to say

if (timeLeft < 0) {
document.location = &quot;login.asp&quot;
}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Yes, thanks, I already had a routine that when the session runs out the pages get redirect to the login.asp page.
But the piece of code you post for the display of remaining time is very very helpfull as it is what I wanted.

Thanks again and happy programming :)

Cheers
 
can someone be so kind to break this down for me and how it flows?

also
is it possible to add

You're cookie will expire in the time remaining

 
tyvm mwolf00, how do I display the remaining time on the page not on the status bar?

 
<script>
var timeLeft = 30 * 60
function startTimer(){
timeLeft --
if (timeLeft < 0) {
document.location = &quot;sessionExpired.asp&quot;
}
minsLeft = Math.floor(timeLeft / 60)
secsLeft = timeLeft - (minsLeft * 60)
if (secsLeft < 10){
secsLeft = &quot;0&quot; + secsLeft
}
document.timeForm.expires.value = minsLeft + &quot;:&quot; + secsLeft + &quot; until your session expires.&quot;
timerID = setTimeout(&quot;startTimer()&quot;,1000)
}
</script>
<body onLoad=&quot;startTimer()&quot;>
<form name=&quot;timeForm&quot;>
<input name=&quot;expires&quot; style=&quot;border: 0px; width: 250px;&quot; readonly>
</form>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
or;
<script>
var timeLeft = <%=session.timeout%> * 60
function startTimer(){
timeLeft --
if (timeLeft < 0) {
document.location = &quot;sessionExpired.asp&quot;
}
minsLeft = Math.floor(timeLeft / 60)
secsLeft = timeLeft - (minsLeft * 60)
if (secsLeft < 10){
secsLeft = &quot;0&quot; + secsLeft
}
document.getElementById('expires').innerHTML = &quot;Your cookie will expire in <span style=\&quot;color:red;font-weight:bold;\&quot;>&quot; + minsLeft + &quot;:&quot; + secsLeft + &quot;</span>&quot;;
timerID = setTimeout(&quot;startTimer()&quot;,1000)
}
</script>
<body onLoad=&quot;startTimer()&quot;>
<div id=&quot;expires&quot; style=&quot;border: 0px; width: 250px;&quot;></div>
</body>

just to get it out of the input box and onto the page itself..
apologies for code cannibalising!!

--------------------------------------------------
- better than toast.
Penguins - better than --------------------------------------------------
 
Is it possible to put this script inside an IF/THEN statement to only show up at a specified time say the last 5 min before the session times out?

Thanks!
Jordan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top