Session issue |
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.
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.
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.
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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.
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. |
Welcome Guest, Not a member yet? Register Sign In |