Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

logout programmatically with joomla

Tags:

php

module

joomla

I need to customize a method in a component. I need to make different action (deleting a user and other info) and then logout the user programmatically (not with a button link), how can I achieve this?

I've tried to do this at the end of the method:

$return   = JRoute::_('index.php?option=com_users&task=user.logout', true);
$this->setRedirect($return,$msg);

But this gives a invalid token message.

Thanks

like image 657
user1075778 Avatar asked Dec 01 '11 15:12

user1075778


2 Answers

What Joomla version are you working on? If it's Joomla 1.7, you can do this in your code:

$app = JFactory::getApplication();
$app->logout( $user_id );

Where $user_id is the ID of the user you want to log out. If you leave it empty or do not set it, it will logout the user that's performing the request. For Joomla 1.5, you can do it the same way, but in Joomla 1.5 there's a global variable named $mainframe that holds an instance of the app, so you can do:

global $mainframe;
$mainframe->logout( $user_id );

I hope it helped!

like image 144
alghimo Avatar answered Oct 05 '22 22:10

alghimo


$app = JFactory::getApplication();
$app->logout();
like image 42
András Avatar answered Oct 05 '22 20:10

András