getLoginUserID

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

API:getLoginUserID

Description / Usage

integer getLoginUserID( );

Determines if user is logged in, be it via the admin 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 Admin Interface, the value returned will be the Admin Interface 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.