Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regarding setCookie and user agent #4

Open
jeromekang opened this issue Jun 4, 2013 · 9 comments
Open

regarding setCookie and user agent #4

jeromekang opened this issue Jun 4, 2013 · 9 comments

Comments

@jeromekang
Copy link

hi, I was trying to use this library for my Remember Me checkbox, and after doing all the steps.. the information is not being inserted into the ci_cookies table.. now after trying to debug the problem, i've traced it to the insertdata array..

$insertdata = array(
'cookie_id' => $cookie_id,
'ip_address' => $ip_address,
'user_agent' => $this->CI->agent->agent_string(),
'netid' => $netid,
'created_at' => date('Y-m-d H:i:s'),
'orig_page_requested' => $orig_page_requested,
'php_session_id' => session_id()
);

i tried printing all the stuff out and the $this->CI->agent->agent_string() is causing the code to stop (also not printing anything)

@joeauty
Copy link
Owner

joeauty commented Jun 4, 2013

That's weird... Was the autoload config file altered to not load the CodeIgniter user agent library?

@jeromekang
Copy link
Author

hi, sorry.. the problem was my fault.. didn't have spark installed..the info is inserting now.. i can't seem to make it work though.. whenever i login my account.. and then close my browser.. i visit the site again and it doesn't remember me

@joeauty
Copy link
Owner

joeauty commented Jun 4, 2013

Is it recording data to ci_cookies now?

@jeromekang
Copy link
Author

yes it's inserting

@joeauty
Copy link
Owner

joeauty commented Jun 4, 2013

I'm going to be debugging this library shortly, every once in a while I've come across what I think might be a bug where a cookie is dropped for some unknown reason. However, if this is never working for you, it sounds like the problem might be with your application code. Can you please paste in the code you are using?

@jeromekang
Copy link
Author

so this is where i validate the checkbox in the login with the email address being the $net_id:

                    if($this->input->post('remember_me') == "1"){
                        $this->rememberme->setCookie($int_email);
                    }

then, i placed the verifyCookie() in a core Controller which is extended by my main controller:

            $this->load->library('rememberme');
            $cookie_user = $this->rememberme->verifyCookie();
            if ($cookie_user) {               
                $this->load->model('user_model');
                $user = $this->user_model->getUserId($cookie_user);
                $this->session->set_userdata('login_session', $user);
                $this->user = $user;
            }
            else if ($this->session->userdata('user_id')) {
                $this->user = $this->session->userdata('user_id');
            }

@grahammccarthy
Copy link

Also, when my validate() function runs to log a user in for the first time,
the rememberme.php library's set_cookie() is called, and i've done some debugging and found that the following code does fire.

            // set cookie for 1 year
            $cookie = array(
                'name' => 'rmtoken_' . str_replace('.', '_', $_SERVER['SERVER_NAME']),
                'value' => $cookie_id,
                'expire' => 31557600,
                'domain' => $domain,
                'path' => preg_replace('/^(http|https):\/\/(www\.)?' . $_SERVER['SERVER_NAME'] . '/', '', preg_replace('/\/$/','', base_url())),
                'secure' => isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : 0
            );

            $this->CI->input->set_cookie($cookie);

I'm still not sure why if the cookie is set here, the validateCookie() can't see it.

@grahammccarthy
Copy link

whoops. my comment above was for issue #2 where i'm discussing a problem with setting the cookie, and not being able to retrieve the user from the verifyCookie() function.

@Dreamystify
Copy link

This is how i check the remember checkbox in my model post data:

// check if remember me was checked...
$remember_me = $this->input->post('rememberme', true);
$checked = $remember_me ? 1: 0; // I store a lot of checked data in a tinyint field in the db this way

The I check "$checked ==1" and so forth, I have no issues with this spark :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants