views:

55

answers:

1

Hi,

I want to make it possible for the administrator to log in as a fontend user from the backend. Right now I'm using two sessions (sessions with different names), one for the admin and one for the frontend.

Is it possible to write in the first session, close it and then open a new session?

This is a simplified version of what I attempted but failed:

session_name('admin_session');
session_start();
// use first session without generatring any output
session_close();

session_name('frontend_session');
session_start();
// use the second session

Thanks.

+1  A: 

I have provided the facility for an administrator to switch to a "user" in the past.

I did this by serializing the admin user's $_SESSION and then storing that string as $_SESSION['adminData'] before overwriting all the other session vars with those of the user he was logging in as, and redirecting to the main page. The only different feature on the main page was an if test against $_SESSION['adminData'] that provided a "revert to admin" link... but to all intents and purposes, the administrator was now logged in as that user. On clicking the "revert to admin" link, the code logic simply unserialized $_SESSION['adminData'].

Mark Baker