Page Session Countdown Timer

Discussion in 'Javascript' started by MC, Mar 22, 2008.

  1. MC

    MC Guest

    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?

    Google has again failed me ;)

    MC
    MC, Mar 22, 2008
    #1
    1. Advertising

  2. MC

    Evertjan. Guest

    MC wrote on 22 mrt 2008 in comp.lang.javascript:

    > 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?


    Session is a serverside concept.
    Clientside, thee is not such a thing as a session timeout.

    > Google has again failed me ;)


    Do you want Google to write your programming?
    It will cost you!


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 22, 2008
    #2
    1. Advertising

  3. MC

    MC Guest

    Evertjan,

    I have to say your wrong. A javascript can track every time a page loads,
    and knowing the session timeout, calculate an approximate, hopefully +- less
    than one second, session timeout.

    I would like to, given a timeout such as 30 minutes, have a countdown from
    the onload event. It would then be nice to prompt the user to logout or
    continue the session by sending a message back to the server to refresh the
    session.

    I say your wrong, because session timeouts ARE being done currently in many
    websites such as banks. ...and I never suggested Google write my code, but
    that Google search find an appropriate example.

    Please troll someplace else if you have nothing constructive to add.

    MC

    "Evertjan." <> wrote in message
    news:Xns9A69AE97BA7ECeejj99@194.109.133.242...
    > MC wrote on 22 mrt 2008 in comp.lang.javascript:
    >
    >> 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?

    >
    > Session is a serverside concept.
    > Clientside, thee is not such a thing as a session timeout.
    >
    >> Google has again failed me ;)

    >
    > Do you want Google to write your programming?
    > It will cost you!
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)
    MC, Mar 22, 2008
    #3
  4. MC

    sasuke Guest

    On Mar 22, 8:16 pm, "MC" <mica[removethis]@aisus.com> wrote:
    > 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?
    >
    > Google has again failed me ;)
    >
    > MC


    Here is a simple script which you can modify as per your needs with a
    little bit of Javascript knowledge.

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=UTF-8" />
    <meta http-equiv="Script-Content-Type" content="text/javascript" /
    >

    <title>Example</title>
    <script type="text/javascript">
    var t = 10; /* This would come from PHP */
    var decr = 1;
    var handle = null;
    var e = null;
    function startTimer() {
    if(!e)
    e = document.getElementById("time");
    e.innerHTML = t;
    handle = setInterval(function() {
    if(t == 0) {
    clearInterval(handle);
    /* do what you want when the timer expires */
    window.location.href = "http://www.google.com/";
    }
    else {
    t -= decr;
    e.innerHTML = t;
    }
    }, decr * 1000);
    }
    window.onload = startTimer;
    </script>
    </head>
    <body>
    <div>The time remaining is <span id="time"></span></div>
    </body>
    </html>

    HTH
    sasuke, Mar 22, 2008
    #4
  5. In comp.lang.javascript message <Xns9A69AE97BA7ECeejj99@194.109.133.242>
    , Sat, 22 Mar 2008 16:09:49, Evertjan. <>
    posted:
    >MC wrote on 22 mrt 2008 in comp.lang.javascript:
    >
    >> 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?

    >
    >Session is a serverside concept.
    >Clientside, thee is not such a thing as a session timeout.


    A client can count down for a length of time indicated by the server;
    and can occasionally be synchronised with the server's opinion.

    >> Google has again failed me ;)


    Try "Good countdowns" as your search string.
    As a contrast, seek countdowns on .gov sites.

    TD09690 : Until 03 September 2081 10:07:31 LCT : 26827d 11h 54m 56s .

    --
    (c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
    Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
    PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
    Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
    Dr J R Stockton, Mar 22, 2008
    #5
  6. MC

    Evertjan. Guest

    MC wrote on 22 mrt 2008 in comp.lang.javascript:
    > "Evertjan." <> wrote in message
    > news:Xns9A69AE97BA7ECeejj99@194.109.133.242...
    >> MC wrote on 22 mrt 2008 in comp.lang.javascript:
    >>
    >>> 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?

    >>
    >> Session is a serverside concept.
    >> Clientside, thee is not such a thing as a session timeout.
    >>
    >>> Google has again failed me ;)

    >>
    >> Do you want Google to write your programming?
    >> It will cost you!


    [Please do not toppost on usenet]

    > I have to say your wrong. A javascript can track every time a page
    > loads, and knowing the session timeout, calculate an approximate,
    > hopefully +- less than one second, session timeout.


    No it cannot, as there could be another call in that session resetting
    the sererside timeout counter.

    Clientside cannot know that, unless it pols the server by ajax or alike
    to ask the present value of the timeout counter. Under ASP it is not even
    available, I suspect the same goes for PHP, but I don't know.

    > I would like to, given a timeout such as 30 minutes, have a countdown
    > from the onload event. It would then be nice to prompt the user to
    > logout or continue the session by sending a message back to the server
    > to refresh the session.


    You cwertainly can do that, but it does not reflect the session state.

    > I say your wrong, because session timeouts ARE being done currently in
    > many websites such as banks.


    Those sites heavily rely on serverside, I hope.

    > ...and I never suggested Google write my
    > code, but that Google search find an appropriate example.


    You did not suggest anything of the sort, though I might be what was in
    your mind. You only said Google had failed you. If that was about
    searching and not about the share value, it could also be that your
    searching skills were not perfect. How would we know?

    > Please troll someplace else if you have nothing constructive to add.


    So now you become abusive, thinking this NG is your personal helpdesk and
    by asking Qs you have a right to dictate the answers?

    My aswer was constructive, showing you you asked the wrong Q an prompting
    you to a better one.

    A countdown timer in Javascript, you simply could have asked for that,
    is a simple affair, can be written within 10 minutes. But you did not ask
    for that.

    If you stay polite, maybe someone will help you.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 22, 2008
    #6
  7. MC

    MC Guest

    Sasuke,

    Thank you. This should work quite nicely! I will be able to show the user
    how much time is left on the page till timeout. I should be able to even
    'show' a form saying they are going to time out in soon, and give them the
    opportunity to refresh the session with a button there.

    Thank you for helping!
    MC
    MC, Mar 22, 2008
    #7
  8. MC

    Evertjan. Guest

    Dr J R Stockton wrote on 22 mrt 2008 in comp.lang.javascript:

    >>Session is a serverside concept.
    >>Clientside, thee is not such a thing as a session timeout.

    >
    > A client can count down for a length of time indicated by the server;
    > and can occasionally be synchronised with the server's opinion.
    >


    However, John, the server, under ASP at least,
    does not know at the scripting level,
    what the countdown status of the session timer is,
    so much for the server's opinion.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 22, 2008
    #8
  9. "Evertjan." <> writes:

    > However, John, the server, under ASP at least,
    > does not know at the scripting level,
    > what the countdown status of the session timer is,
    > so much for the server's opinion.


    That can't be right. There may be no direct way of querying that info,
    but one would assume the timeout is configurable (and so, knowable) and
    reset at each page request. Which is all you'd need to know for doing
    this fairly accurately.

    --
    Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
    Joost Diepenmaat, Mar 22, 2008
    #9
  10. MC

    MC Guest

    Joost,

    Exactly what I was thinking...given a timeout such as 30 minutes, a client
    page onload should be able to approximate the timeout. I have seen several
    examples of this on bank sites. It doesn't matter if its ASP, JSP, PHP, or
    CF. Just that the client is passed or stored in the page what the timeout
    will be.

    MC
    MC, Mar 23, 2008
    #10
  11. MC

    sasuke Guest

    On Mar 23, 4:05 am, "MC" <mica[removethis]@aisus.com> wrote:
    > Sasuke,
    >
    > Thank you. This should work quite nicely! I will be able to show the user
    > how much time is left on the page till timeout. I should be able to even
    > 'show' a form saying they are going to time out in soon, and give them the
    > opportunity to refresh the session with a button there.
    >
    > Thank you for helping!
    > MC


    Glad I was able to help. Hope it all works out well for you. :)
    sasuke, Mar 23, 2008
    #11
  12. MC

    Evertjan. Guest

    Joost Diepenmaat wrote on 23 mrt 2008 in comp.lang.javascript:

    > "Evertjan." <> writes:
    >
    >> However, John, the server, under ASP at least,
    >> does not know at the scripting level,
    >> what the countdown status of the session timer is,
    >> so much for the server's opinion.

    >
    > That can't be right.


    But it is, Joost.

    > There may be no direct way of querying that info,
    > but one would assume the timeout is configurable (and so, knowable) and
    > reset at each page request. Which is all you'd need to know for doing
    > this fairly accurately.


    Not fairly at all.

    If the user does alt-N and has two duplicate pages, and clicks to another
    site page from the second page 15 minutes later, the first page will show
    the session is gone, while the session lives on happily [though not ever
    after], and the session can be used from the page with the counter that
    tells you it cannot.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 23, 2008
    #12
  13. "Evertjan." <> writes:

    > Not fairly at all.
    >
    > If the user does alt-N and has two duplicate pages, and clicks to another
    > site page from the second page 15 minutes later, the first page will show
    > the session is gone, while the session lives on happily [though not ever
    > after], and the session can be used from the page with the counter that
    > tells you it cannot.


    Yeah that's true. There are ways of working around this problem, of
    course. Provided you've got enough control of the session mechanism at
    the server side you could just do a periodic Ajax request to check the
    session status.

    I still don't know what you mean about the *server* scripts not knowing
    what the session timer is. Sounds like a really strange restriction to
    me.

    --
    Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
    Joost Diepenmaat, Mar 23, 2008
    #13
  14. MC

    Evertjan. Guest

    Joost Diepenmaat wrote on 23 mrt 2008 in comp.lang.javascript:

    > "Evertjan." <> writes:
    >> Not fairly at all.
    >>
    >> If the user does alt-N and has two duplicate pages, and clicks to
    >> another site page from the second page 15 minutes later, the first
    >> page will show the session is gone, while the session lives on
    >> happily [though not ever after], and the session can be used from the
    >> page with the counter that tells you it cannot.

    >
    > Yeah that's true. There are ways of working around this problem, of
    > course. Provided you've got enough control of the session mechanism at
    > the server side you could just do a periodic Ajax request to check the
    > session status.
    >
    > I still don't know what you mean about the *server* scripts not
    > knowing what the session timer is. Sounds like a really strange
    > restriction to me.


    Ours is not to ask the why of the language/platform at implementation
    time,
    just to implement it.

    ASP cannot read the actual state of the session timeout counter.
    PSP probably has the same restriction.

    The only time that you know it's state is at the reset moment.

    You could test by Ajax if the session is still active,
    but that would be done "destructively",
    as the counter is reset by the test.

    Kind of a quantum measurement dilemma, isn't it?

    > Provided you've got enough control of the session mechanism


    You could forego the server internal session mechanism,
    [which depends on a session cookie, btw],
    and build your own session with a database.
    Then you can read the last session reset time from that database.

    That probably is the way some banks do their work, having an session-id
    in the querystring, and no cookies necessary for that.

    The above shows a timeout timer is not even necessary, only a comparison
    of 'now' to the last resettime at every new html request [and some sort
    of database garbage collection sql execution now and then].


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 23, 2008
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Stewart

    GUI countdown timer in a JApplet?

    Ryan Stewart, Dec 23, 2003, in forum: Java
    Replies:
    2
    Views:
    863
  2. JSP countdown timer

    , Nov 1, 2005, in forum: Java
    Replies:
    4
    Views:
    14,763
  3. KennethGorelick

    Countdown Timer

    KennethGorelick, Feb 19, 2006, in forum: Python
    Replies:
    2
    Views:
    568
    KennethGorelick
    Feb 19, 2006
  4. Dirk Hagemann

    Countdown timer for different timezones

    Dirk Hagemann, Jul 6, 2006, in forum: Python
    Replies:
    1
    Views:
    470
    Marc 'BlackJack' Rintsch
    Jul 6, 2006
  5. Michael J.

    Need special kind of countdown timer

    Michael J., Aug 27, 2003, in forum: Javascript
    Replies:
    0
    Views:
    110
    Michael J.
    Aug 27, 2003
Loading...

Share This Page