Results 1 to 21 of 21

Thread: Getting Session Time remaining

  1. #1
    Member
    Real Name
    roberto
    Join Date
    Aug 2008
    Posts
    68

    Default Getting Session Time remaining

    Is there a way to determine a user's actual session time remaining. Serversetting.session_timeout only gives the max value but I need the countdown of time remaining.

    In v9, I could rely on a variable set on a Submit or an onLoad event to determine the last user activity (database read/update). With v10 and AJAX, users can be active without triggering a Submit or an onLoad event.

    For security reasons, I want users logged out if their session is not in use. But I want to give users on warning before there session expires. I am trying to use a javascript setTimeout() to display a warning before there session ends and they are logged out. The code looks something like this:

    Code:
    <script type="text/javascript"> 
     var c = 555;  //dummy value to prevent premature warning
     function timeoutCheck(){
       if (c<=15){
         // alert user to expiring session
       }
       c =  " <%a5 ?  serversetting.session_timeout %> "   
       //when I check the value of "c" it always shows the session lifetime of 900
       t=setTimeout("timeoutCheck()",5000)  // check the session timeout every 5 seconds.
     }
    </script>
    Is my logic flawed? Is there a better way to do this?

    Thanks, Roberto

  2. #2
    Member
    Real Name
    Pratheep Moorthy
    Join Date
    Feb 2011
    Posts
    40

    Default Re: Getting Session Time remaining

    Hi Roberto, did you find an answer to this? I am also seeing that serversetting.session_timeout only returns the lifetime of 900. Thanks!

  3. #3
    Member
    Real Name
    Pratheep Moorthy
    Join Date
    Feb 2011
    Posts
    40

    Default Session Time out

    Is there any function I can use to get how much time is left before a session timeout? I tried using serversetting.session_timeout as Alphapedia says this gives "The number of seconds before a session times out." But this always gives me 900 which is the timeout I have set for the server. Anyone know how I can get the time remaining? Thanks!

  4. #4
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,103

    Default Re: Session Time out

    The amount of time before session timeout is different for each user, depending on their activity. The session time resets to full amount each time they refresh their browser or, on recent versions of A5, if they run any AJAX activity. If you want to warn a person that their session is about to expire, you need a client side javascript routine that will independently count down the seconds, perpahs warn them with an alert 1 minute before.
    Steve Wood
    Web Mobile Hosting Products
    President at AlphaToGo and IADN (100% Alpha Five Websites)
    Titter: alphatogo

  5. #5
    Member
    Real Name
    roberto
    Join Date
    Aug 2008
    Posts
    68

    Default Re: Session Time out

    pvin2011, No I have not received an answer to this.

    Steve, How do you know "any" ajax activity resets the session time? Is it possible not all ajax activity resets the session time? It would be preferable to query the application server directly for the user's actual session time remaining.

  6. #6
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,369

    Default Re: Session Time out

    Quote Originally Posted by roberto View Post
    Steve, How do you know "any" ajax activity resets the session time? Is it possible not all ajax activity resets the session time? It would be preferable to query the application server directly for the user's actual session time remaining.
    Any activity received from a specific client by the server restarts the session timer on the server for that session. It is not possible to interrogate the server to find out how much time is left for the session, because doing so would reset the timer. As Steve said, you would need to maintain a timer in the client.
    Last edited by Lenny Forziati; 05-20-2011 at 01:03 PM.

    Lenny Forziati
    Vice President, Internet Products and Technical Services
    Alpha Software Corporation

  7. #7
    Member
    Real Name
    roberto
    Join Date
    Aug 2008
    Posts
    68

    Default Re: Getting Session Time remaining

    I suspected it was not possible to query the app server for remaining time, but I wanted to be sure. Thanks for the info.

  8. #8
    Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,103

    Default Re: Getting Session Time remaining

    Steve, How do you know "any" ajax activity resets the session time?
    Because I remember where it was discussed and someone from Alpha, probably Lenny, clarified that it did.

    To answer what you need to do to measure reamining session time, search for "javascript remaining web session timeout" or similar. There are dozens of examples of javascript code - alerts, or a countdown in the status bar, etc.

    I don't know how to do all of this but I think the ideal is:

    1) show a popup alert when the session is about to expire, tell them to click OK to continue
    2) have that OK button do an ajax callback which would reset the session timeout and allow them to continue uninterupted
    3) if they did not click OK by time the session did time out, close the popup, fire the A5 logout function, and send them to a page that says "you were logged out due to inactivity..."

    That seems to be what my bank does.
    Steve Wood
    Web Mobile Hosting Products
    President at AlphaToGo and IADN (100% Alpha Five Websites)
    Titter: alphatogo

  9. #9
    "Certified" Alphaholic kingcarol's Avatar
    Real Name
    Carol King
    Join Date
    Jun 2010
    Posts
    1,299

    Default Re: Getting Session Time remaining

    I wasn't able to accomplish what you are attempting, but did end up using this idea and it's working well for me:
    http://javascript.internet.com/page-...-time-out.html
    Carol King
    Developer of Custom Homebuilders' Solutions (CHS)
    http://www.CHSBuilderSoftware.com

  10. #10
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    461

    Default Re: Getting Session Time remaining

    I just wanted to chime in and post my solution using jQuery and jQuery UI.

    It basically sets a call for the showDialog javascript function to run after the `time` variable runs out (1.74 million ms is 29 minutes). When the showDialog() function is called it creates a jquery ui dialog that displays nicely. A second timer starts as a countdown for 60 seconds and replaces the text in the #timeout-countdown span every second. If the user click `Yes, Keep Working` then an ajax callback to `keepWorking.a5w` is called. The contents of that file are insignificant, we really just need to ping the WAS to prevent session timeout. After the callback the dialog is closed, and all the timers are reset. If the user clicks `No, Logoff` then the user is forwarded to `logout.a5w` which includes session deletion and the xbasic logout function (also some sql logging stuff). This also happens when the #timeout-countdown time reaches 0.

    FYI, the WAS session timeout needs to be GREATER than this timeout so that when a user clicks `Yes` or `No` the session is actually still alive. One single second should suffice, but I think my WAS timeout is like 5 minutes longer than the javascript timeout. My thinking for this is that the WAS should NEVER timeout a session itself. I ALWAYS want my logoff.a5w page to be called so I can terminate a session properly and cleanly. I've had quite a few complaints that they come back to the application, type up a bunch of stuff, click save only to find out their session had timed out and they lost all they typed.

    ALSO, I've already set jQuery to be in no conflict mode with this code
    Code:
    var $j = jQuery.noConflict(true);
    Code:
    <link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css" />
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
    <!-- Timeout Dialog -->
    <div id="timeout" style="display:none;" title="Your session is about to expire!">
    	<p>You will be logged off in <span id="timeout-countdown">60</span> seconds.</p>
    	<p>Would you like to keep working?</p>
    </div>
    <script type="text/javascript">
            //Timeout dialog
    
    	// time = timeout time in milliseconds. 1.74m is 29 minutes
    	var time = 1740000;
    	// countdown = time in seconds for the session timeout dialog to show before action is taken.
    	var timeout = 60;
    	// logout = the inital set of the showDialog function to show the jquery ui dialog.
    	var logout = setInterval( function(){showDialog()} , time );
    	
    	function showDialog(){
    
    		$j('#timeout').dialog({
    			autoOpen:true,
    			width: 500,
    			modal:true,
    			closeOnEscape:false,
    			draggable:false,
    			resizable:false,
    			buttons: {
    				'Yes, Keep Working': function(){
    					// resume once clicked
    					$j.ajax({
    						url: "keepAlive.a5w",
    						cache: false,
    						success: function(){
    							//clear and reset the timers
    							$j('#timeout').dialog('close');
    							$j('#timeout-countdown').text(timeout);
    							clearInterval(logout);
    							clearInterval(timer);
    							logout = setInterval( function(){showDialog()} , time );
    						}
    					});
    				},
    				'No, Logoff': function(){
    					window.location = "logout.a5w";
    				}
    			}
    		});
    		
                    // this will countdown starting from the number written in the #timeout-countdown span.
    		var timer = setInterval(function() {
    			var countdown = $j('#timeout-countdown').text() || 0;
    			$j('#timeout-countdown').text(--countdown);
    			if (countdown == 0){
    				//timeout! timer hit zero, log the user out.
    				window.location = "logout.a5w";
    				clearInterval(timer);
    			}
    		}, 1000);
    
    	}
    </script>
    The positive of using this code instead of Carol's code above is that we don't have to change pages to keep our session active.

  11. #11
    VAR
    Real Name
    Mike Reed
    Join Date
    Apr 2000
    Location
    Phoenix, AZ
    Posts
    510

    Default Re: Getting Session Time remaining

    Hi,
    Can you tell me where to place these 2 pieces of code in the a5w page?

    Thanks,
    Mike
    Mike Reed
    Phoenix, AZ

  12. #12
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    461

    Default Re: Getting Session Time remaining

    It would need to be in the <head> section

  13. #13
    Member
    Real Name
    Edhy Rijo
    Join Date
    Sep 2012
    Location
    Bronx NY
    Posts
    274

    Default Re: Getting Session Time remaining

    Hi Sparticuz,
    Quote Originally Posted by Sparticuz View Post
    It would need to be in the <head> section
    I am using a TabbedUI as the main page of my application and tried to put this code in the "Header text" property, but it did not work, then tried in the auto-generated TabbedUI.a5w page, but it was erased after a modification to the TabbedUI control, so where exactly can we paste this code?

    Quote Originally Posted by Sparticuz View Post
    If the user clicks `No, Logoff` then the user is forwarded to `logout.a5w` which includes session deletion and the xbasic logout function (also some sql logging stuff). This also happens when the #timeout-countdown time reaches 0.
    Also, with a5V11 do we have to delete the session? if so, could you please post a sample code on how to do that?

    Thanks!!!!
    Last edited by Progytech; 01-14-2013 at 07:09 PM.

  14. #14
    Member
    Real Name
    Edhy Rijo
    Join Date
    Sep 2012
    Location
    Bronx NY
    Posts
    274

    Default Re: Getting Session Time remaining

    Hi all,
    I found the answers to my question in another posts:

    For the TabbedUI, I should use the code in the "User defined 'head' content property. Posted by Carol Kind here...

    And to delete the session, use the session.reset() method in my Logout.a5w page. Posted by Steve Wood here...

    As always, thanks a lot to the community for the sharing!!!

  15. #15
    Member
    Real Name
    Edhy Rijo
    Join Date
    Sep 2012
    Location
    Bronx NY
    Posts
    274

    Default Re: Getting Session Time remaining

    Hi All,

    One question, using Sparticuz solution in post 10 above, would it be possible to implement playing a .wav sound file to alert the user when showing the dialog window?

    I tried to implement this using code from here using my own wav file but it never played out. In this link there is even a test button to play the sound.

    Code:
    Dynamic HTML allows you to use JavaScript to write new HTML code into your page and let it be interpreted by the browser. The trick to using dynamic HTML for sound replay is to write into a region of the document the HTML of an embedded sound set to automatically start replay on load. Here we are going to use a <span> region and write into it using its "innerHTML" attribute:
    
        function DHTMLSound(surl) {
          document.getElementById("dummyspan").innerHTML=
            "<embed src='"+surl+"' hidden=true autostart=true loop=false>";
        }
    
    We can now create the dummy span region and just pass the URL of the sound file to the function to play it:
    
        <span id=dummyspan></span>
        <form>
        <input type="button" value="Play Sound" onClick="DHTMLSound('success.wav')">
        </form>

  16. #16
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    461

    Default Re: Getting Session Time remaining

    Look into this: http://www.w3schools.com/html/html5_audio.asp

    You'd need to add an audio element into the div. Then you'd basically need to add an 'onOpen' jquery dialog event that would start the audio element.

  17. #17
    Member
    Real Name
    Edhy Rijo
    Join Date
    Sep 2012
    Location
    Bronx NY
    Posts
    274

    Default Re: Getting Session Time remaining

    Thanks Sparticuz,

    I am not very familiar with jquery, but will investigate your suggestion and see how to incorporate it in the dialog.
    By the way, this jquery solution has been very well accepted by my end users and I would like to formally thank you for sharing your experience with us.

  18. #18
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    461

    Default Re: Getting Session Time remaining

    Really! My users hate it! "Why are we always getting kicked out!!!" They ask. I've since (against my will) increased the amount of time to 90 minutes.

    Anyways, here is what you'd want:
    Code:
    <div id="timeout" style="display:none;" title="Your session is about to expire!">
    	<p>You will be logged off in <span id="timeout-countdown">60</span> seconds.</p>
    	<p>Would you like to keep working?</p>
    	<audio style="display:hidden;" id="expire-ping">
    		<source src="ping.ogg" type="audio/ogg">
    		<source src="ping.mp3" type="audio/mpeg">
    	</audio>
    </div>
    
    $j('#timeout').dialog({
    	autoOpen:true,
    	open: function(event,ui){$j('#expire-ping').trigger('play');},
    	close: function(event,ui){$j('#expire-ping').trigger('stop');},
    	width: 500,
    	modal:true,
    	closeOnEscape:false,
    Note: This is code I just wrote, you'll have to add it into the rest of your code, not sure if it actually works or not. Please post results and what you had to do to get it working!
    (don't forget to change the src of the audio elements.)

  19. #19
    Member
    Real Name
    Edhy Rijo
    Join Date
    Sep 2012
    Location
    Bronx NY
    Posts
    274

    Default Re: Getting Session Time remaining

    Hi Sparticuz,

    Sorry but it did not work. I added the code as instructed, change the src file and published my wav file to the root folder and it just not play, I tested in several browsers that support the wav.

    About my users, they like this functionality because before, the session will just expire on them without a warning and when they tried to continue working the forms just did not respond, so with this warning at least they know what is going on.
    Code:
    <audio controls style="display:hidden;" id="expire-ping">
    	<source src="LogOutWarningSound.wav" type="audio/wav">
    </audio>

  20. #20
    Member
    Real Name
    Sparticuz
    Join Date
    Jun 2009
    Location
    Clearwater, FL
    Posts
    461

    Default Re: Getting Session Time remaining

    Hmm, I'm not sure, I'd look more into jquery, the audio tag, and how they interact. Please post if you solve it. :)

  21. #21
    Member
    Real Name
    Edhy Rijo
    Join Date
    Sep 2012
    Location
    Bronx NY
    Posts
    274

    Default Re: Getting Session Time remaining

    Hi,
    Nope I have not been able to make it work either.

Similar Threads

  1. total of time fields (short time format)
    By jrtarrago in forum Alpha Five Version 9 - Desktop Applications
    Replies: 1
    Last Post: 02-10-2010, 09:27 AM
  2. Session DBF in side of Session Folder
    By ColinJD in forum Application Server Version 9 - Web/Browser Applications
    Replies: 2
    Last Post: 08-24-2009, 12:42 AM
  3. Set Session Expiry time in Application server
    By Vasan in forum Application Server Version 9 - Web/Browser Applications
    Replies: 3
    Last Post: 02-13-2009, 03:35 AM
  4. Resetting Days Remaining
    By Richard Rabins in forum Alpha Five Version 7
    Replies: 13
    Last Post: 10-26-2005, 09:35 AM
  5. Part time or full time Alpha Develoeprs
    By Henry Rothschild in forum Announcements
    Replies: 5
    Last Post: 06-26-2004, 02:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

The Reviews Are In...

It just is revolutionary and reminds me of VB and how it changed the world.
quote Robert Scoble, Scobleizer

...Version 10 is a turning point on how developers will be writing applications for the web
quote Alan Ashendorf, Lets Talk Computers

Alpha Five version 10... this version is really a break-through for web developers.
quote The Wall Street Journal, Digital Network

Our Professional Services Division

Training and Mentoring - Alpha Software's Professional Services division is here to help. We offer mentoring and training services, for those who need guidance or advice building their own applications.

Development Services - Need someone to build your application? We'll get the job done right. We have an in-house team of Alpha Five developers and a network of carefully selected artists, designers and IT professionals ready to handle projects of any size. Read more .

submit a project request

Alpha Five Awards & Press
awards
Products Store Support Services About Cart Site Map Resources Home
© Copyright 2000-2011 Alpha Software, Inc. 70 Blanchard Road Burlington, MA 01803 781.229.4500
more