Created
November 21, 2017 18:53
-
-
Save buluma/beabaea47c830c834aae1eaad56221dc to your computer and use it in GitHub Desktop.
Joomla Direct Logout Link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Since I have a habit of forgetting things, I'll keep this here: | |
The following link is for direct logout: | |
http://example.com/index.php?option=com_users&task=user.logout | |
But a user token is required in order to avoid an error message Invalid Token, and some PHP magic is required in order to get the token. The following code will display a Login link to guests, and a direct Logout Username link to logged in users: | |
$user = JFactory::getUser(); | |
if ($user->guest) | |
{ | |
echo '<a href="index.php?option=com_users&view=login">Login</a>'; | |
} | |
else | |
{ | |
$userToken = JSession::getFormToken(); | |
echo '<a href="index.php?option=com_users&task=user.logout&' . $userToken . '=1">Logout ' . $user->username . '</a>.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment