Q: how to use codeigniter library for login log out I have created library in codeigniter library and it's named account. I want to get all session data when I call this library, how can I do that. I tried this:
if ($this->account->isLoggedIn()){
    $this->ci->session->userdata('isLoggedIn');
}


A: First Include the Library:
$this->load->library('session');

Store the data in array which you want to store in session :
$data= array(
                   'username'  => 'username',
                   'password'     => 'password',
                   'email'=>'emailid'
                   'logged_in' => 'login id'
               );

Store this data in session:
$this->session->set_userdata($data);

You can use this data any time for example if you want loginid from session you can write:
$loginid= $this->session->userdata('logged_in');

When Logout:
$this->session->unset_userdata(array("username"=>"","logged_in"=>"","password"=>"","email"=>""));
$this->session->sess_destroy();
redirect('loginpage');

If you don't want to direct access the pages create one model and add this code in it and auto load that model.
public function valid_allowed()//check user is login or not
    {
        $session = $this->session->userdata('username'); //here you can take loginid, email whatever you store in session
        if(!$session)
        {
            redirect('login');
        }
    }

To auto load that model
Go to application->config->autoload.php: this line:
$autoload['model'] = array('model name');

Change your model:
class LoginModel extends CI_model
        {
            public function login($name, $pass)
            {
                $this->db->select('name,pass');
                $this->db->from('members');
                $this->db->where('name',$name);
                $this->db->where('pass',$pass);     

                $query = $this->db->get();

                if($query->num_rows() == 1)
                {
                    $row=$query->row();
                    $data=array(
                    'username'=>$row->u_username,
                    'id'=>$row->id,
                    'email'=>$row->email
                    'password'=>$row->u_password);
                    $this->session->set_userdata($data);
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

Change your verifyUser function:
public function verifyUser()
                        {
                            $name = $this->input->post('username');
                            $pass = $this->input->post('password');

                            $this->load->model('LoginModel');
                            $result=$this->LoginModel->login($name, $pass))
                         if(!$result)                   
                         {

             $this->form_validation->set_message('verifyUser','Incorrect Email or Pass');
                                return false;
                     redirect('LoginController/checklogin');

                        }
                        else
                        {   
                           redirect('dashboard');   //user is valid so goto dashboard
                        }
}

