Welcome Guest, Not a member yet? Register   Sign In
How to creat remember me checkbox with codeigniter?
#1

[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.
#2

[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.
#3

[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.




Theme © iAndrew 2016 - Forum software by © MyBB