Use javascript to determine if the user is logged into Joomla
I have a joomla page which updates regularly using AJAX. Depending on other (external) events, the user may get logged out of the site. I would like to be able to tell fro开发者_如何学Cm Javascript whether the user is (still) logged in. I am looking for some sort of Javascript function which will make a call to the server and will return true if the user is logged in or false if they are not logged in.
Thanks for any ideas.
Here's how to fire a controller function in your component using jQuery.
$.post("index.php?option=com_mycomponent", {task: "checkUserStatus", username: "chuck"},
function(data)
{
//do something with your 'data' response here
});
Just as reminder - make sure and close the mainframe at the end of your controller function, otherwise Joomla will render the whole component and flush the output to the data variable.
function checkUserStatus()
{
//do your PHP code to check user status
echo $response;
global $mainframe;
$mainframe->close();
}
精彩评论