Welcome Guest, Not a member yet? Register   Sign In
return cookie value
#4

[eluser]ibnclaudius[/eluser]
I'm doing this, if the user login with the remember me checked, create a cookie and insert it in database, the database part is ok, but I don't if the cookie is being set. Confused
Code:
public function login($email, $password, $remember)
{
  $email = trim($email);
  $password = sha1(trim($password));
  
  $user = $this->CI->auth_mod->login($email, $password);
  
  if ($user)
  {
   if ($this->roles['active'] === TRUE && $user['active'] === FALSE)
   {
    echo $this->errors['not_active'];
   }
   else
   {
    $session = array(
      'logged' => TRUE,
      'id' => $user['id'],
      'name' => $user['name'],
      'email' => $user['email'],
      'active' => $user['active']
    );
    
    $this->create_user_session($session);
    
    if ($this->remember['active'] === TRUE && $remember === $this->remember['name'])
    {
     $token = sha1(uniqid(rand(), TRUE));
    
     $this->CI->auth_mod->create_user_session($user['id'], $token);
    
     $cookie = array(
         'name'   => $this->remember['name'],
         'value'  => $token,
         'expire' => '86500',
         'domain' => '',
         'path'   => '/',
         'prefix' => '',
         'secure' => TRUE
       );

     $this->CI->input->set_cookie($cookie);
    }
    
    redirect($this->redirects['logged'], 'location');
   }
  }
  else
  {
   echo $this->errors['invalid_login'];
  }
}

So, when the user logout, delete his session and if there's a cookie, delete it and from the database, but again, everything works, except the cookie part, it's not deleted, also from the database... I don't know if the cookie is being set..
Code:
public function logout()
{
  $this->CI->session->sess_destroy();
  
  $session_token = $this->CI->input->cookie($this->remember['name']);
  
  if ($session_token)
  {
   $this->auth_mod->delete_user_session($session_token);
  }
  
  redirect($this->redirects['logged_out'], 'location');
}

Sorry for the english Confused


Messages In This Thread
return cookie value - by El Forum - 04-05-2012, 02:21 PM
return cookie value - by El Forum - 04-05-2012, 05:16 PM
return cookie value - by El Forum - 04-06-2012, 11:21 AM
return cookie value - by El Forum - 04-06-2012, 11:57 AM
return cookie value - by El Forum - 04-06-2012, 04:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB