Actions

API15

Difference between revisions of "JApplication/logout"

From Joomla! Documentation

< API15:JApplication
(New page: ===Description=== Logout authentication function. <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki>]</now...)
 
m (removing red link to edit, no existant pages)
 
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JApplication/logout|Edit Descripton]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
  
{{Description:JApplication/logout}}
+
<! removed transcluded page call, red link never existed >
  
 
===Syntax===
 
===Syntax===
Line 23: Line 23:
 
| $options
 
| $options
 
| array()
 
| array()
|  $options Array('clientid' => array of client id's)  
+
|  $options Array( 'clientid' => array of client id's )
 
|}
 
|}
  
Line 33: Line 33:
 
===Source Body===
 
===Source Body===
 
<source lang="php">
 
<source lang="php">
public function logout($userid = null, $options = array())
+
function logout($userid = null, $options = array())
 
{
 
{
         // Initialise variables.
+
         // Initialize variables
 
         $retval = false;
 
         $retval = false;
  
         // Get a user object from the JApplication.
+
         // Get a user object from the JApplication
 
         $user = &JFactory::getUser($userid);
 
         $user = &JFactory::getUser($userid);
  
         // Build the credentials array.
+
         // Build the credentials array
 
         $parameters['username'] = $user->get('username');
 
         $parameters['username'] = $user->get('username');
 
         $parameters['id']              = $user->get('id');
 
         $parameters['id']              = $user->get('id');
  
         // Set clientid in the options array if it hasn't been set already.
+
         // Set clientid in the options array if it hasn't been set already
         if (empty($options['clientid'])) {
+
         if(empty($options['clientid'])) {
 
                 $options['clientid'][] = $this->getClientId();
 
                 $options['clientid'][] = $this->getClientId();
 
         }
 
         }
  
         // Import the user plugin group.
+
         // Import the user plugin group
 
         JPluginHelper::importPlugin('user');
 
         JPluginHelper::importPlugin('user');
  
         // OK, the credentials are built. Lets fire the onLogout event.
+
         // OK, the credentials are built. Lets fire the onLogout event
 
         $results = $this->triggerEvent('onLogoutUser', array($parameters, $options));
 
         $results = $this->triggerEvent('onLogoutUser', array($parameters, $options));
  
Line 63: Line 63:
 
         */
 
         */
 
         if (!in_array(false, $results, true)) {
 
         if (!in_array(false, $results, true)) {
                // Use domain and path set in config for cookie if it exists.
+
                 setcookie( JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, '/' );
                $cookie_domain = $this->getCfg('cookie_domain', '');
+
                $cookie_path = $this->getCfg('cookie_path', '/');
+
                 setcookie(JUtility::getHash('JLOGIN_REMEMBER'), false, time() - 86400, $cookie_path, $cookie_domain );
+
 
                 return true;
 
                 return true;
 
         }
 
         }
  
         // Trigger onLoginFailure Event.
+
         // Trigger onLoginFailure Event
 
         $this->triggerEvent('onLogoutFailure', array($parameters));
 
         $this->triggerEvent('onLogoutFailure', array($parameters));
  
Line 78: Line 75:
  
 
<span class="editsection" style="font-size:76%;">
 
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JApplication/logout|Edit See Also]]<nowiki>]</nowiki>
+
<nowiki>[<! removed edit link to red link >]</nowiki>
 
</span>
 
</span>
{{SeeAlso:JApplication/logout}}
+
<! removed transcluded page call, red link never existed >
  
 
===Examples===
 
===Examples===
 +
Log the current user out
 +
<source lang="php">
 +
$app = JFactory::getApplication();             
 +
$user = JFactory::getUser();
 +
$user_id = $user->get('id');           
 +
$app->logout($user_id, array());
 +
</source>
 
<CodeExamplesForm />
 
<CodeExamplesForm />
 
<dpl>
 
<dpl>
Line 93: Line 97:
 
  format= ,,,
 
  format= ,,,
 
</dpl>
 
</dpl>
 +
[[Category:Archived pages API15]]

Latest revision as of 08:34, 12 May 2013

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Logout authentication function.

[<! removed edit link to red link >]

<! 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 edit link to red link >] <! 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());

<CodeExamplesForm />