Welcome Guest, Not a member yet? Register   Sign In
Destroying and then setting session data
#1

[eluser]Unknown[/eluser]
I'm new to CI and this is driving me mad...I'm missing something.

I need to create a back door into my application so that admins can log in as any user.

I've created a user model with a login() and logout() as follows:
Code:
public function login($login){
  $user = $this->get_by(array('login' => $login), TRUE);

  if(count($user) > 0){
   $data = array(
    'id' => $user->customerId
    'login' => $user->login,
    'loggedin' => TRUE,
    'admin' => $user->admin
   );

   $this->session->set_userdata($data);

   return TRUE;
  }
}

public function logout(){
  $this->session->sess_destroy();
}

I also have a door man as follows in my user controller:
Code:
public function doorman()
{
  if(isset($_GET['user'])){
   // log out
   $this->user_m->logout();

   // log in
   if($this->user_m->login($_GET['user']) === TRUE){
    // redirect
    redirect('dashboard');
   }
  }
}

If I access user/doorman?user=blahblah, I get to the redirect but none of the user data sticks when I call $this->session->all_userdata(). In particular $this->session->userdata('loggedin') returns false.

Seems to me logout destroys the session, and login creates a new one, ready to use on the next request.

Any insights as to why this isn't working?
#2

[eluser]boltsabre[/eluser]
Have you done an echo inside if(count($user) > 0){ to make sure you're actually getting a $user?
Or better yet, doing a var_dump($data) just before you set it into the session?




Theme © iAndrew 2016 - Forum software by © MyBB