简体   繁体   中英

Problems with Codeigniter Session Class

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)

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.

You could have done it like this

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM