Best practice forum (Archived)

How to get ID of admin logged in as another user

 
John Unnever
How to get ID of admin logged in as another user
על ידי John Unnever בתאריך 9/01/2016, 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!!

Simon Coggins
Re: How to get ID of admin logged in as another user
על ידי Simon Coggins בתאריך 11/01/2016, 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

John Unnever
Re: How to get ID of admin logged in as another user
על ידי John Unnever בתאריך 11/01/2016, 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.