From Joomla! Documentation

< API16:JApplication

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.


Logout authentication function.

<! removed transcluded page call, red link never existed >


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



jimport( 'joomla.application.application' );

Source Body

public function logout($userid = null, $options = array())
        // Initialise 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.

        // 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)) {
                // Use domain and path set in config for cookie if it exists.
                $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;

        // Trigger onLoginFailure Event.
        $this->triggerEvent('onLogoutFailure', array($parameters));

        return false;

<! removed transcluded page call, red link never existed >


Code Examples