AnsweredAssumed Answered

Is it possible to log in as another user?

Question asked by KarlMetum KarlMetum on Jun 25, 2014
Latest reply on Sep 8, 2015 by KarlMetum KarlMetum
Is it possible to login as another user?
If I'm logged in as an Admin, I want to be able to login as user2 without having to supply his/her password. In v6, this was possible with this code snippet:

<?phpglobal $current_user, $db; 
if( ! $current_user->is_admin)
    if(empty($_SESSION['was_admin']))
        die('Need to be administrator to access'); 
if( ! empty($_GET['user_id']))
{
    $_SESSION['user_id'] = $_GET['user_id']; 
    $_SESSION['authenticated_user_id'] = $_GET['user_id'];
    $_SESSION['was_admin'] = true;
    
    $user = new User(); 
    $user->retrieve($_GET['user_id']);
    $current_user = $user; 
    header('Location: index.php?module=Home');
}
$sql = "SELECT id, user_name, first_name, last_name FROM users WHERE deleted = 0 AND is_group = 0";
$resultset = $db->query($sql);
while($row = $db->fetchByAssoc($resultset))
{
    echo '<a href="index.php?module=Administration&action=SwitchUser&user_id=' . $row['id'] . '"> ' . $row['user_name'] . '</a> '.$row['first_name'].' ' . $row['last_name'] .' <br/><br/>';
}
?>

I'm not sure how to do this in V7.X

Outcomes