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

[eluser]Cálcio[/eluser]
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:

Code:
set_cookie(array(
            '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.

Tnks.
#2

[eluser]InsiteFX[/eluser]
Why are you using $this->ci ? You only need that if your loading it in a libaray etc not in a controller.
#3

[eluser]Cálcio[/eluser]
So, I have a method in my controller, that verify if the cookie exist.
Something like that:

Code:
/**
     * 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
if($this->autologin())
{
  return STATUS_ACTIVATED;
}
else
{
  return $this->ci->session->userdata('status') === ($activated ? STATUS_ACTIVATED : STATUS_NOT_ACTIVATED);
}
    }

This verification return true or false.
#4

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

[eluser]Cálcio[/eluser]
hum ok.
But my CI version is old (1.7.2). Is it a problem? Can I use the same way that you wrote?
#6

[eluser]InsiteFX[/eluser]
It should not be a problem and yes us it the way I showed you...




Theme © iAndrew 2016 - Forum software by © MyBB