Switching between users on the fly

Tips submitted by PHPMaker users

Switching between users on the fly

Postby Adam » Mon May 15, 2017 3:07 pm

Our support staff needed a way to quickly and easily log in as clients without needing to:

1) log out themselves
2) use a secondbrowser
3) obtain the client's credentials

...so we added a snippet of jQuery to the footer of the project that presented a "Log in as..." or "Resume as..." button on particular pages (in each row of the users' List/Grid page, and on the View page).

We then added a snippet of PHP to the header:

// switch from admin/staff to a regular profile
if (CurrentUserLevel() != 1 && isset($_GET['SetProfile'])) {
$_SESSION['_ROOT_PROFILE'] = array(
'SysAdmin' => $_SESSION['YourProject_SysAdmin'],
'Level' => $_SESSION['YourProject_status_UserLevel'],
'ID' => $_SESSION['YourProject_status_UserName']
);
$_SESSION['YourProject_SysAdmin'] = 0;
$_SESSION['YourProject_status_UserLevel'] = 0;
unset($_SESSION['YourProject_status_UserLevelValue']);
$_SESSION['YourProject_status_UserName'] = (int) $_GET['SetProfile'];
$_SESSION['YourProject_status_UserProfile_UserName'] = (int) $_GET['SetProfile'];
header("Location: your_default_page.php");
exit;
}
// resume to admin/staff from a regular profile
else if (CurrentUserLevel() == 0 && isset($_GET['ResumeRootProfile']) && isset($_SESSION['_ROOT_PROFILE'])) {
$_SESSION['YourProject_SysAdmin'] = $_SESSION['_ROOT_PROFILE']['SysAdmin'];
$_SESSION['YourProject_status_UserLevel'] = $_SESSION['_ROOT_PROFILE']['Level'];
$_SESSION['YourProject_status_UserName'] = $_SESSION['_ROOT_PROFILE']['ID'];
$_SESSION['YourProject_status_UserProfile_UserName'] = $_SESSION['_ROOT_PROFILE']['ID'];
unset($_SESSION['_ROOT_PROFILE']);
header("Location: your_default_page.php");
exit;
}
Adam
 
Posts: 109
Joined: Wed Jan 09, 2013 7:53 pm

Return to User Submitted Tips (PHPMaker)