php更改记录管理员作为用户和返回

I have php application with admin and user access. What i want to do is this;

while logged in as admin, I need to click on a button and login as a user without login off from admin panel. Form the user control panel i want to be able to click for example "Back to Admin" button and login as admin. I need to remain loged all the time only to swap between user and admin control panel . I have my sessions set as folowing:

    Session::init();
        Session::set('role', $data['role']);
        Session::set('userid', $data['userid']);
        Session::set('language', $data['language']);
        Session::set('loggedIn', TRUE);

if ($data['role'] == "admin") {
          header('location: ' . URL . 'spadmincp');
        } elseif ($data['role'] == "owner") {
          header('location: ' . URL . 'dashboard');
        } elseif ($data['role'] == "default") {
          header('location: ' . URL . 'userservices');
        } elseif ($data['role'] == "reseller") {
          header('location: ' . URL . 'reseller');
        }
      } else {
        header('location:' . URL . 'login   ');
      }

I will appreciate any help

Thanks

You can try this. On Admin Panel put the link to got to the user panel.

Eg.

<a href="Your user panel url">Go To User Panel</a>

And at user panel.

Check if it is admin and display the back to admin button.

 if($_SESSION['role']=='admin')

echo 'Back to admin';

also at user panel you may add. access to admin or user during security check.

Why don't you store an adminuserid in your session and use that at the admin pages and use the userid on the not-admin pages?

try to put a last_role and last_userid variable in the session, when the admin change the user save his role/userid, give him the new ones, when he switch back clear the last ones, after he got back his own credintials.