JApplication/logout: Difference between revisions
From Joomla! Documentation
m →Examples: - Adding Example |
m preparing for archive only |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
Logout authentication function. | Logout authentication function. | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
| Line 74: | Line 72: | ||
</source> | </source> | ||
<! removed transcluded page call, red link never existed > | |||
< | |||
===Examples=== | ===Examples=== | ||
| Line 87: | Line 83: | ||
$app->logout($user_id, array()); | $app->logout($user_id, array()); | ||
</source> | </source> | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=logout | category=logout | ||
category=JApplication | category=JApplication | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API15]] | |||
Latest revision as of 00:17, 25 March 2017
Description
Logout authentication function.
<! removed transcluded page call, red link never existed >
Syntax
logout($userid=null, $options=array())
| Parameter Name | Default Value | Description |
|---|---|---|
| $userid | null | $userid The user to load - Can be an integer or string - If string, it is converted to ID automatically |
| $options | array() | $options Array( 'clientid' => array of client id's ) |
Defined in
libraries/joomla/application/application.php
Importing
jimport( 'joomla.application.application' );
Source Body
function logout($userid = null, $options = array())
{
// Initialize variables
$retval = false;
// Get a user object from the JApplication
$user = &JFactory::getUser($userid);
// Build the credentials array
$parameters['username'] = $user->get('username');
$parameters['id'] = $user->get('id');
// Set clientid in the options array if it hasn't been set already
if(empty($options['clientid'])) {
$options['clientid'][] = $this->getClientId();
}
// Import the user plugin group
JPluginHelper::importPlugin('user');
// OK, the credentials are built. Lets fire the onLogout event
$results = $this->triggerEvent('onLogoutUser', array($parameters, $options));
/*
* If any of the authentication plugins did not successfully complete
* the logout routine then the whole method fails. Any errors raised
* should be done in the plugin as this provides the ability to provide
* much more information about why the routine may have failed.
*/
if (!in_array(false, $results, true)) {
setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/' );
return true;
}
// Trigger onLoginFailure Event
$this->triggerEvent('onLogoutFailure', array($parameters));
return false;
}
<! removed transcluded page call, red link never existed >
Examples
Log the current user out
$app = JFactory::getApplication();
$user = JFactory::getUser();
$user_id = $user->get('id');
$app->logout($user_id, array());
Code Examples