Tech Blog

Make MetaLib sessions stay alive (not time out)

  • Description
    A bit of JavaScript and a few other changes to make MetaLib sessions not timeout.  These changes allow MetaLib sessions to stay alive as long as the user has MetaLib open in the browser.
  • Institution: None
  • Year: 2009
  • License: BSD style
  • Short description: Use, modification and distribution of the code are permitted provided the copyright notice, list of conditions and disclaimer appear in all related material.
  • Skill required for using this code: Basic

State

Stable

Programming language

Javascript

Author(s) homepage

http://wiki.helsinki.fi/display/Nelli/Etusivu

 

Working example

http://www.nelliportaali.fi/finelib

 

Release notes

The following changes make the browser send a request to MetaLib at specified interval to keep the session from timing out. Normal MetaLib session timeout will occur, if user navigates away from MetaLib or closes the browser, or if JavaScript is not available.
This method is compatible with most browsers. The ActiveXObject stuff is Internet Explorer only, but other browsers don’t need it.

Installation instructions

1. Edit www_v_eng/meta-tags (and other languages)

 

a. Remove the following row

 

<meta http-equiv="refresh" content="$8500; url=&server_vir?func=exit">

 

This will prevent the redirection to the exit page.
        b. Add the following piece of javascript at the of the file:
<script type="text/javascript">
<!--
/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
function XMLHttpRequest() { return new ActiveXObject('Microsoft.XMLHTTP'); }
@end @*/

function keepalive()
{
  var xml = new XMLHttpRequest();
  xml.open("GET", "&server_vir?func=file&file_name=keepalive", true);
  xml.send(null);
  window.setTimeout(keepalive, 600*1000);
}
window.setTimeout(keepalive, 600*1000);
-->
</script>

 

        c. If your session timeout in MetaLib is set to less than 10 minutes, change the number 600 in the code to a lower value (it is the number of seconds between “pings” sent to MetaLib to keep the session alive)
2.  Create a keepalive file in www_v_eng (and other language codes) with the following command:

 

echo > keepalive

 

Known issues

This will slightly skew web server access statistics, if there are a lot of idle sessions hanging around.

Leave a Reply