Best practice forum (Archived)

How to get ID of admin logged in as another user

 
UnneverJohn
How to get ID of admin logged in as another user
UnneverJohn 发表于 2016年01月9日 Saturday 08:23
小组 Partners

I know you can use the global USER variable to get information based on who is currently logged in, but how can i get information on the ADMIN who is "logged in as" a user?   I'm doing some custom development and we have a situation where our admins might need to log in as a user and perform some actions on their behalf, and i need to record which admin is performing the task when i insert the record of action in the db.

I'm assuming this information is available considering when you log in as another user, it shows both user account names in the upper right user menu, i'm just not sure how i should access it.

Thanks for your help!!

CogginsSimon
Re: How to get ID of admin logged in as another user
CogginsSimon 发表于 2016年01月11日 Monday 10:55
小组 Totara

Looking at the login_info() function in lib/outputrenderers.php it looks like there are two methods of interest to you:

\core\session\manager::is_loggedinas()

\core\session\manager::get_realuser();

These are both defined in the file lib/classes/session/manager.php.

Simon

UnneverJohn
Re: How to get ID of admin logged in as another user
UnneverJohn 发表于 2016年01月11日 Monday 20:05
小组 Partners

Thanks Simon..  you're a wealth of information!  Looks like i can grab  the user full name pretty easily..  gonna try and figure out how to get the userid since that might be better for getting an audit log.