Session issue - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6) +--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19) +--- Thread: Session issue (/showthread.php?tid=69561) |
Session issue - yinkoh - 12-14-2017 Hello, I'm getting confused with a session issue... I'm using a parent controller (MY_Controller) for all others controllers. Each of them is correctly initiated with parent::__construct() and everything is going well. Right now, I'm doing the backoffice part of my site and so, I need to store a flag for identified users. PHP Code: class MY_Controller extends CI_Controller PHP Code: class Backoffice extends MY_Controller My problem is that session always gets empty unless I do not use the CI Session library and therefore uses $_SESSION from native php. I just dont get what part is wrong in my code. Ps: I've tried using both files or database driver in application/config/config.php but without any changes. RE: Session issue - dave friend - 12-14-2017 In the code you show this is the problem PHP Code: $this->session->set_userdata('is_logged' => 1); Try this instead PHP Code: $this->session->set_userdata('is_logged', 1); Or this if you really want to use an array PHP Code: $this->session->set_userdata(['is_logged' => 1]); If you are using a Codeigniter version > 3 then you can use $_SESSION directly. If you read the documentaion carefully you will see that is recommended. PHP Code: $_SESSION['is_logged'] = 1; To check for session data I like this approach PHP Code: public function index() If you are certain that session data was set but it isn't showing up in index() then you probably have an improper session and/or cookie configuration. RE: Session issue - yinkoh - 12-15-2017 You're right about the code mistake but in the actual code, i set the proper way to store the data, i just write it down wrongly. I tried your code just in case but I still get the same problem. I'm gonna try to check it on a new install of the lastest CI to see if it's not a config file related issue. RE: Session issue - InsiteFX - 12-15-2017 Did you try to autoload the session? ./application/config/autoload.php Makes no since adding it to a MY_Controller if your going to use it all the time. RE: Session issue - dave friend - 12-15-2017 Quote:Makes no since adding it to a MY_Controller if your going to use it all the time. Except perhaps unless MY_Controller is always used. RE: Session issue - yinkoh - 12-15-2017 Well, starting of a fresh new install of ci solved the trouble... I still dont get it but at least i can keep on coding Thanks everyone. |