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.
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;
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