Switching between users on the fly

Tips submitted by PHPMaker users
Post Reply
Adam
User
Posts: 480

Switching between users on the fly

Post by Adam »

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;
}


jaypolmx
User
Posts: 8

Post by jaypolmx »

Can this be used on any PHPMaker version?


Adam
User
Posts: 480

Post by Adam »

The principle should hold up, but I doubt the code will. However, it shouldn't take much effort to get it going.

Unfortunately, I haven't got to that point in the v2020 upgrade yet, so I can't tell you what works and what doesn't.

I'll post any updates once I get to that code, but feel free to experiment and share your findings.


saleh
User
Posts: 470

Post by saleh »

hello

Where do I put the code?


Adam
User
Posts: 480

Post by Adam »

As explained in the notes, that sample code goes in the page header, but you'll still need to write some JS/jQuery to place the activation button somewhere logical for your purposes.


Post Reply