<!-- admin_login_as_user.php -->
<?php
session_start();
include '../_db.php'; // Database connection

// include 'head.php';

// Check if the userid is provided
if (isset($_GET['userid'])) {
    $userid = $_GET['userid'];

    // Query to get user details
    $sql = "SELECT * FROM user_login WHERE userid = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("s", $userid);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        // Fetch user data
        $user = $result->fetch_assoc();

        // Set session variables for the user
        $_SESSION['user_logged_in'] = true;
        $_SESSION['userid'] = $user['userid'];
        $_SESSION['username'] = $user['username']; // Assuming username is available

        // Redirect to the user dashboard
        header("Location: ../dashboard.php");
        exit;
    } else {
        echo "User not found.";
    }
} else {
    echo "Invalid request.";
}
?>
