getLoginUserID

Last edited by JP DeVries on Aug 10, 2013.

API:getLoginUserID

API Quick reference
Variable name: getLoginUserID
Modx versions: 0.9.x + Evolution
Input parameters:  
Return if successful: Logged in user ID
Return type: int
Return on failure:  
Object parent: DocumentParser

Description / Usage

integer getLoginUserID( );

Determines if user is logged in, be it via Manager Interface, or Web Interface, and returns the ID (int) of the current user. If no user is logged in, null is returned.

  • $context can be either 'web' or 'mgr'. Returns nothing if the user is not logged in.

Returns current user id.

Examples

// In the front end, returns an array of the logged in user's attributes.
    $userInfo = $modx->db->getRow(
        $modx->db->select(
            "*",
            $modx->db->getFullTableName('web_user_attributes'),
            "`internalKey`=".$modx->getLoginUserID()
        )
    );

Notes

In the manager, the value returned will be the manager user's ID.

Function Source

File: manager/includes/document.parser.class.inc.php
Line: 2015

function getLoginUserID($context= '') {
        if ($context && isset ($_SESSION[$context . 'Validated'])) {
            return $_SESSION[$context . 'InternalKey'];
        }
        elseif ($this->isFrontend() && isset ($_SESSION['webValidated'])) {
            return $_SESSION['webInternalKey'];
        }
        elseif ($this->isBackend() && isset ($_SESSION['mgrValidated'])) {
            return $_SESSION['mgrInternalKey'];
        }
    }

Suggest an edit to this page on GitHub (Requires GitHub account. Opens a new window/tab).