Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a button to close active session in joomla 2.5

I need to create a button to log out in Joomla, I mean, the user usually enter the session but then must press the button I created to close this session, I know how to check if any user has entered the session and I know how to display the button, what I don't know is how to make that button close the actual user session (log out).

This is the base code I have:

<?php $user =& JFactory::getUser(); ?>
<?php if ( ($user->id)==0 ) : ?>

    //***code for not opened session***

<?php else : ?>

    <form id="form1" name="form1" method="post" action="">
      <input type="button" name="button" id="button" value="Close Session" />
    </form>

<?php endif ?>

How to make that button to close the joomla 2.5 session, I checked the API page but i didn't find it.

like image 846
Elessar Alcarin Avatar asked Dec 12 '25 01:12

Elessar Alcarin


2 Answers

To create a log out button, you could create a link with the class "button".

In Joomla > 1.7 (also 2.5.x) you need the JUtility::getToken() part to make the login successful: Use the optional "return" part for redirecting the user back to the page where the user was when clicking the button

<a class="button" href="<?php echo JRoute::_('index.php?option=com_users&task=user.logout&'. JUtility::getToken().'=1'); ?>">
    Logout
</a>

If you want to redirect back to the page where the user was when he/she clicked the logout button, add a base64 encoded return parameter:

<a class="button" href="<?php echo JRoute::_('index.php?option=com_users&task=user.logout&'. JUtility::getToken().'=1&return='.base64_encode(JURI::current())); ?>">
    Logout
</a>
like image 196
Beatniak Avatar answered Dec 14 '25 14:12

Beatniak


the correct link is actually

JRoute::_('index.php?option=com_users&task=user.logout&'. JUtility::getToken() .'=1');
like image 40
Richie Avatar answered Dec 14 '25 15:12

Richie