1

this is my problem... I added to the construct of CI_Controller these lines

    $this->load->library("session");
    if($this->session->userdata("var")==FALSE)
    {
        $this->session->set_userdata("var", "value");   
    }

And when I use $this->session->userdata("var") in a child class, it doesn't have a value. I tested that by showing the value of $this->session->userdata("var") in the construct of CI_COntroller and in the construct of the child class and it shows me the value on the father but no on the child.

There is another thing, after reload the page about 3 or 4 times. It works very well.

I will be grateful for your answers. (And I'm sorry I'm not an English speaker)

10
  • Are you using cookies or storing in the database? Commented Mar 8, 2013 at 17:19
  • mmmm... I use the library session of codeigniter, does not it work with cookies?... I don't understand you Commented Mar 8, 2013 at 17:22
  • The Session library stores data in cookies by default, unless you set the config to use the database to store sessions. Commented Mar 8, 2013 at 17:24
  • oh I see... so I'm using cookies Commented Mar 8, 2013 at 17:26
  • Can you check Firebug or the Webkit console to see if you're getting a Set-Cookie response header on the request? Commented Mar 8, 2013 at 17:28

2 Answers 2

1

you should do

$this->load->library("session");
    if(!$this->session->userdata("var"))
    {
        $this->session->set_userdata("var", "value");   
    }

cause userdata() method returns false and true if isset or not session data.

Sign up to request clarification or add additional context in comments.

2 Comments

Aren't !$var and $var == FALSE same expression?
@kidonchu anyway best practice is the one i showed u above in my answer ;)
0

You could have done it like this

$this->load->library("session");

$var    =   $this->session->userdata("var");

if(!$var)
{
    $this->session->set_userdata("var", "value");   
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.