DISCLAIMERS:
- because the original post is already locked, I post this as the continuation of that post.
- this method pose a very major security issue, maybe that's why the function is pulled off from the core
- Considering that this is a hack. Use this at your own risk (!!! intentional multiple exclamation marks), I will take no responsibility whatsoever if you do this.
- When you are done doing this, revert back to the original /course/loginas.php sooner than later.
Okay, with that out of the way:
For a project I am working on, I need to do 'login as' multiple times and it drives me nuts after doing it for 5 users. The current 'login as' function will log out out altogether if you click logout while posing as the other user (student). What I need / want is to go back to my original admin user so I can move on to the next user.
I found the loginas.php from the post in 2013, and the code has been changed of course. What I changed to get it working again:
- line 10: session_loginas() is now \core\session\manager::is_loggedinas()
- line 81: session_loginas($userid, $context); is now \core\session\manager::loginas($userid, $context);
- line 84: add_to_log() is commented out -- fully realizing that this is a hack and very temporary at that, I am fully aware to ignore the logging.
Here's the file: https://pastebin.com/raw/aFWX0DFY