Welcome Guest, Not a member yet? Register   Sign In
Cannot set cookie for Remember me
#1

[eluser]Unknown[/eluser]
Hi All,

I am trying to implement the "Remember me" feature for login but I cannot set the cookie to store information.

Here is sample of my code:

Code:
function login(){
    $emailid = trim($this->input->post('log_email', TRUE));//Email entered by user
    $password = trim($this->input->post('log_pass', TRUE));//Password entered by user
    $rem_me_flag=$this->input->post('rem_me');//Remember me checkbox value
        
        $this->load->model('Login_model');

        //Get user information in array user)info
        $user_info=$this->Login_model->check_login($emailid, $password);
        

        $username=$user_info['name'];
        $user_id=$user_info['encrypted_uid'];
        
        if($username!=""){//login details are right
            //set session
            $this->session->set_userdata('loggedin_user_name', $username);
            
            //if remember me is checked
            if($rem_me_flag==true){
            
                //Set cookie
                $cookie = array(
                    'name'   => 'bu_user_id',
                    'value'  => $user_id,
                    'domain' => '.localhost',
                    'expire' => '1209600',
                    'path'   => '/',
                    'secure' => TRUE
                );
                $this->input->set_cookie($cookie);            
            }
            
            //return ok
            echo "ok";
        }else{
            echo "error";
        }
    }

I thought maybe .localhost is the problem. So, I removed the 'domain' parameter but still no success. What can be the issue?

Thanks.
#2

[eluser]InsiteFX[/eluser]
secure is used only when using https!

InsiteFX
#3

[eluser]Unknown[/eluser]
Thanks a lot. That solved the issue.

So, while deploying all I need to do is to change my domain name from localhost to my own domain name. (right?)
#4

[eluser]InsiteFX[/eluser]
Yes, and make sure you put a . period in front of it!

InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB