CodeIgniter Forums
How to creat remember me checkbox with codeigniter? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to creat remember me checkbox with codeigniter? (/showthread.php?tid=50616)



How to creat remember me checkbox with codeigniter? - El Forum - 04-02-2012

[eluser]Unknown[/eluser]
Hello,
I have this code in header to login:
Code:
echo form_open('login');
    echo form_input("email","email");
    echo form_password("password","");
    echo form_submit("ok","ok");
    echo form_hidden('url',current_url());
    echo form_close();
and this is the login function in controller:
Code:
function login(){
        $this->load->model('my_mod');
  
        $email = $this->input->post('email');
        $password = $this->input->post('password');
        $url = $this->input->post('url');
        $user = $this->my_mod->user_exist_employer($email,$password);

        $user = $this->my_mod->user_exist($email,$password);
        if($user!=false){
foreach($user as $user):
        $data = array(
                   'fname'  => $user->fname,
                   'lname'  => $user->lname,
                   'id' => $user->id,
                   'logged_in' => true
               );

        $this->session->set_userdata($data);
endforeach;
        redirect($url);
    }
}

and I wonder how to put checkbox (remember me) like any website.



How to creat remember me checkbox with codeigniter? - El Forum - 04-02-2012

[eluser]InsiteFX[/eluser]
CodeIgniter Users Guide - Form_helper check_box

In order to do a remember me you will need to create a cookie on the users system if they cheeck the check box!

Then in your login code you need to first check and see if they do have a cookie for remember me if they do auto log them into the system else show them the login screen!

I create a hash code using their username and password and save that into cookie and their database record.



How to creat remember me checkbox with codeigniter? - El Forum - 04-02-2012

[eluser]boltsabre[/eluser]
Code:
$user = $this->my_mod->user_exist_employer($email,$password);

        $user = $this->my_mod->user_exist($email,$password);

Careful of this, your second call to your model is over writing the results of your first model call because you've called both $user = $this->my_mod->
If the first model call is just setting some session stuff or whatever, not a problem, but if it's returning anything then yeah... you've over written it.