How to resolve “I am unable to logout from my Joomla website” problem

A new solicitor firm based in the UK signed up for website maintenance with our company. The website had been developed in Joomla and running for the past 1 year. The first issue they reported was that their members were not able to log out from the website even if they clicked on the logout button. They were concerned (and rightly so) that their member’s account could be used to perform any negative activity on the website.

The form code for the logout button was as follows

<form action="index.php" method="post" name="login" id="form-login">
<?php if ($params->get('greeting')) : ?>
<div>
<?php if ($params->get('name')) : {
echo JText::sprintf( 'HINAME', $user->get('name') );
} else : {
echo JText::sprintf( 'HINAME', $user->get('username') );
} endif; ?>
</div>
<?php endif; ?>
<div align="center">
<input type="submit" name="Submit" class="button" value="<?php echo JText::_( 'BUTTON_LOGOUT'); ?>" />
</div>

<input type="hidden" name="option" value="com_user" />
<input type="hidden" name="task" value="logout" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
</form>

After initial assessment I found that the logout code was doing a POST instead of sending the parameters in querystring. Due to this Joomla did not know whether the visitor was trying to logout or not.

I opened the modules/mod_login/tmpl/default.php and changed the form action from POST to GET.

I also added the following hidden field

<input type="hidden" name="view" value="login" />

So the final form code comes out to be as follows

<form action="index.php" method="get" name="login" id="form-login">
<?php if ($params->get('greeting')) : ?>
<div>
<?php if ($params->get('name')) : {
echo JText::sprintf( 'HINAME', $user->get('name') );
} else : {
echo JText::sprintf( 'HINAME', $user->get('username') );
} endif; ?>
</div>
<?php endif; ?>
<div align="center">
<input type="submit" name="Submit" class="button" value="<?php echo JText::_( 'BUTTON_LOGOUT'); ?>" />
</div>

<input type="hidden" name="option" value="com_user" />
<input type="hidden" name="view" value="login" />
<input type="hidden" name="task" value="logout" />
<input type="hidden" name="return" value="<?php echo $return; ?>" />
</form>

I saved the file and the logout started to work fine after that.

Hope the above helped. Comments?

Leave a Comment