3

I want to log out my joomla website when browser close event occurs. I think joomla logout only works when clear session

Please help me.

1 Answer 1

1

This is not tried/tested, so the best implementation is up for debate, but you could load this javascript in your template so that it is included on all pages. When the window closes, it will POST to a PHP script that you will contain the code that does the log out.

window.onbeforeunload = function(){
   // Post to script that will log the user out
   xmlhttp.open("POST","logmeout.php",true);
   xmlhttp.send();
}

Referring to this question and answer, write logmeout.php to include the Joomla Framework, and this code should do the logout:

$app = JFactory::getApplication('site');
if(JFactory::getUser()->id) {
     $app->logout();
}
$app->close;
2
  • Does unbeforeunload only run when the tab is closed, or would this also be triggered when they navigate to a different page? Commented Dec 21, 2014 at 1:56
  • Have a look at this questin/answer stackoverflow.com/questions/3888902/…
    – GDP
    Commented Dec 21, 2014 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.