Force logout on page close

boyjah

Member
Is there a way to logout a user when they close a specific page that contains a Fabrik form?

We have a terms of service form that the logged in user must click the I Agree radio button and then submit. But if they close the page without doing that, we want to automatically log them out.
 
Should the users be logged out when they:

1. Press Cancel button on Fabrik form?
2. Just leave the form open without submitting?
3. When they close browser / browser tab or navigate to another url?
4. All of the above?
 
OK, haven't tested this approach, but it might work. You should be able to do this on beforeunload event which triggers when you navigate away from the form or close the browser window/tab.

First add this e.g. to your form templates default.php file:
Code:
<script>
jQuery(window).on('beforeunload', function(e) {
  //make your ajax call here
  return true;
 });
</script>

and in place of your ajax call you can call a php-script were you destroy the users session like:
Code:
$session = JFactory::getSession();
$session->destroy();

There might be other easier solutions, but I cannot think of any right now.

Of course the easy one would be to set the session lifetime to a very short time like a couple of minutes, but that's probably not what you want.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top