PHP/WordPress Session CountDown
Posted
by Cameron
on Stack Overflow
See other posts from Stack Overflow
or by Cameron
Published on 2010-01-19T17:30:35Z
Indexed on
2010/04/01
14:03 UTC
Read the original article
Hit count: 263
I have the following code to show how long a user has left before their session will expire, I am using WordPress. How can I do this? Thanks
<script>
var obj_Span;
var n_Seconds = 0;
var n_Minutes = 0;
var n_Hours = 0;
function F_ConvertNumberToString ( n_Num )
{
var str_Num = String(n_Num);
if ( str_Num.length < 2 ) str_Num = "0" + str_Num;
return str_Num;
}
function F_CountDown ()
{
if ( n_Hours == 0 && n_Minutes == 0 && n_Seconds == 0 )
{
obj_Span.innerHTML = "(Sorry, your session has expired.)";
}
else
{
if ( n_Seconds >= 0 ) n_Seconds --;
if ( n_Seconds < 0 )
{
n_Minutes --;
n_Seconds = 59;
}
if ( n_Minutes >= 0 )
{
window.setTimeout ( "F_CountDown()", 1000 );
}
if ( n_Minutes < 0 )
{
n_Hours --;
n_Minutes = 59;
window.setTimeout ( "F_CountDown()", 1000 );
}
F_UpdateDisplay ();
}
}
function F_UpdateDisplay ( )
{
if ( document.getElementById )
{
if (n_Hours > 0 ) obj_Span.innerHTML = "(Remaining " + F_ConvertNumberToString(n_Hours) + ":" + F_ConvertNumberToString(n_Minutes) + ":" + F_ConvertNumberToString(n_Seconds) + ")";
else obj_Span.innerHTML = "(Remaining " + F_ConvertNumberToString(n_Minutes) + ":" + F_ConvertNumberToString(n_Seconds) + ")";
}
}
function F_StartCountDown ( n_Session )
{
obj_Span = document.getElementById ( "CountDown" );
n_Minutes = n_Session;
n_Hours = Math.floor(n_Minutes/60);
n_Minutes = n_Minutes - (60*n_Hours);
F_CountDown ();
}
</script>
<script>
F_StartCountDown ( " code here... " );
</script>
<span id="CountDown"></span>
© Stack Overflow or respective owner