Welcome Guest, Not a member yet? Register   Sign In
Problem with cookie

Hi guys.

I have used the cookie from CI using the method $this->ci->load->helper('cookie'); and I'm setting the cookie like this:

            'name' => "autologin",
            'value' => $login,
            'expire' => 5184000,

So, when I print the value using a simple method in my controller, the data return the correct value, however seems the expire time don't work. I think the value the expire is 60 days, but with a few minutes I lost my session.

Someone have a idea for this behavior.


Why are you using $this->ci ? You only need that if your loading it in a libaray etc not in a controller.

So, I have a method in my controller, that verify if the cookie exist.
Something like that:

     * Check if user logged in. Also test if user is activated or not.
     * @param bool
     * @return bool
    function is_logged_in($activated = TRUE) {
        // Try to autologin
  return $this->ci->session->userdata('status') === ($activated ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED);

This verification return true or false.

If it is in a controller you do not need to use $this->ci
And your code should be like this...
return ($this->session->userdata('status') === $activated) ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED;

hum ok.
But my CI version is old (1.7.2). Is it a problem? Can I use the same way that you wrote?

It should not be a problem and yes us it the way I showed you...

Theme © iAndrew 2016 - Forum software by © MyBB